【问题标题】:PROBLEM: Sending email using gmail server问题:使用 gmail 服务器发送电子邮件
【发布时间】:2023-03-07 15:48:01
【问题描述】:

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

警告:mail() [function.mail]:无法在“ssl://smtp.gmail.com”端口 465 连接到邮件服务器,请验证 php.ini 中的“SMTP”和“smtp_port”设置或使用第 141 行 C:\xampp\php\PEAR\Mail.php 中的 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);

【问题讨论】:

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

标签: php gmail


【解决方案1】:

如果你可以投递到本地 Postfix,让 Postfix 投递到 Gmail,你可以试试这个解决方案,我前段时间blogged about

【讨论】:

    猜你喜欢
    • 2016-09-07
    • 2014-05-20
    • 1970-01-01
    • 2022-01-09
    • 2014-10-15
    • 1970-01-01
    • 2012-01-18
    相关资源
    最近更新 更多