简体   繁体   中英

pear mail, setting and using

I am a begginer, so please advise. Facts : try to use pear's mail and make it work. I installed pear, mail, and Net. I use Apache 2.2.22, PHP 5.3.13, Windows 7. The whole system is installed localy on my laptop. Does this makes any difference? Also, I have no clue if my apache supports smtp. I used this as guideline.

This is my code (try to create a simple "forgot my password", not finished)

     <?php
    error_reporting(E_ALL);
//connect to db
     include_once('connection.php');
     include('Mail.php');
    //came from login form
    $logf = $_POST['logf'];  

//query according to logf    
    $stmt = $dbh->prepare("SELECT mail FROM table where usrnm = :nm");
    $stmt->bindParam(':nm', $nm, PDO::PARAM_STR);
    $nm=$logf;

    $data=array('nm'=>$nm);
    $result=$stmt->execute($data);

      $d=0;
      while ($row = $stmt->fetch()) {
      $be[$d]=$row['mail'];
      $d++;}


         $mes="ελα";
            //mail came from query
         $email = $be[0];
         $message = $mes;

         $from = 'Website Enquiry ';
         $to = "Hammy Goonan ";
         $subject = "ανακτηση";
         $body = $message;
         $host = "localhost";
         $headers = array ('From' => $from,
             'To' => $to,
             'Subject' => $subject
         );
         $smtp = Mail::factory('smtp',
             array ('host' => $host,
                 'auth' => false,
                 'port' => '25'
             )
         );
         $mail = $smtp->send($to, $headers, $body);
         if (PEAR::isError($mail)) {echo($mail->getMessage());}
         else {echo("Message successfully sent!");}

    ?>

I get this error :

Failed to connect to localhost:25 [SMTP: Failed to connect socket: , . (code: -1, response: )]

Plese help, I've read tutorials and I dont know how to fix this. Actually, I dont know where to begin.

Thanks.

EDIT I also tried this (example section) that uses sendmail, but i dont understand the following

$params['sendmail_path'] = '/usr/lib/sendmail';

Sendmail also needs smtp erver?

If you want to use localhost as the address for your mail server, localhost has to have a mail server installed.

You need to either install a mail server (there are some development-oriented ones like Devnull ) or (generally easier) just point it at your ISP's SMTP server for sending purposes.

If you are going to use localhost as the address, you will need to make sure that localhost (Your Laptop) has a mailserver installed.

Alternatively, you could use an email sending service like SendGrid and use their SMTP server or as another answer suggest's, point it to your ISP's SMTP server.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM