Php 问题:使用gmail服务器发送电子邮件

Php 问题:使用gmail服务器发送电子邮件,php,gmail,Php,Gmail,有一段时间,我试图使用php脚本和gmail服务器创建和发送自动电子邮件,但我总是遇到以下错误: 警告:mail()[function.mail]:无法连接到位于“”的邮件服务器ssl://smtp.gmail.com“端口465,请验证php.ini中的“SMTP”和“SMTP_端口”设置,或在C:\xampp\php\PEAR\Mail.php的第141行使用ini_set() 这是我的密码: require_once ("mail.php"); ini_set("SMTP","

有一段时间,我试图使用php脚本和gmail服务器创建和发送自动电子邮件,但我总是遇到以下错误:

警告:mail()[function.mail]:无法连接到位于“”的邮件服务器ssl://smtp.gmail.com“端口465,请验证php.ini中的“SMTP”和“SMTP_端口”设置,或在C:\xampp\php\PEAR\Mail.php的第141行使用ini_set()

这是我的密码:

   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 .= "Author: $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);

如果您可以将邮件发送到本地Postfix,并让Postfix发送到Gmail,那么您可以尝试解决方案,我不久前已经尝试过了。

也可以方便地查看mail.php。mail.php是标准类。当您安装php客户端时,它里面有mail.php。(意思是我没有编程)