开发者

PROBLEM: Sending email using gmail server

开发者 https://www.devze.com 2023-03-03 06:57 出处:网络
For some time I was trying to create and send automatic email using php script and gmail server and I always get this error:

For some time I was trying to create and send automatic email using php script and gmail server and I always get this error:

Warning: mail() [function.mail]: Failed to connect to mailserver at "ssl://smtp.gmail.com" port 465, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\xampp\php\PEAR\Mail.php on line 141

Here is my code:

   require_once ("mail.php");
   ini_set("SMTP","ssl://smtp.gmail.com");
   ini_set("SMTP_PORT", 465);
   $to = $sqlmail['email'];
   $from = $fromemail['email'];
   $body = "Hello, \n\n";
   $body .= "This is a request to borrow the following book\n";
   $body .= "Title: $title\n";
   $body .= "Autho开发者_StackOverflow社区r: $author\n";
   $body .= "Year: $year\n";
   $body .= "From the user $_SESSION[username]\n";
   $subject = $title . " " . $author . " " . $year;



   $host = "ssl://smtp.gmail.com";
   $port = "465";
   $username = "slesher.gmail.com";
   $password = "xxxxxxxx";

   $headers = array ('From' => $from,
            'To' => $to,
            'Subject' => $subject);
   $smtp = new Mail();
   $smtp ->factory('smtp',
   array ('host' => $host,
         'port' => $port,
         'auth' => true,
         'username' => $username,
         'password' => $password));

   $mail = $smtp->send($to, $headers, $body);


If you can deliver to a local Postfix and let Postfix deliver to Gmail, you can try the solution, I've blogged about some time ago.

0

精彩评论

暂无评论...
验证码 换一张
取 消