【问题标题】:php mail cannot be sent with smtp.gmail.com [duplicate]无法使用 smtp.gmail.com 发送 php 邮件 [重复]
【发布时间】:2011-11-11 23:02:18
【问题描述】:

可能重复:
PHP mail using Gmail

代码:

<?
    //change this to your email.
    $to = "bhavesh412@gmail.com";
    $from = "bhavesh412@gmail.com";
    $subject = "Hello! This is HTML email";

    //begin of HTML message
    $message = <<<EOF
<html>
  <body bgcolor="#DCEEFC">
    <center>
        <b>Looool!!! I am reciving HTML email......</b> <br>
        <font color="red">Thanks Mohammed!</font> <br>
        <a href="http://www.maaking.com/">* maaking.com</a>
    </center>
      <br><br>*** Now you Can send HTML Email <br> Regards<br>MOhammed Ahmed - Palestine
  </body>
</html>
EOF;
   //end of message
    $headers  = "From: $from\r\n";
    $headers .= "Content-type: text/html\r\n";

    //options to send to cc+bcc
    //$headers .= "Cc: [email]maa@p-i-s.cXom[/email]";
    //$headers .= "Bcc: [email]email@maaking.cXom[/email]";

    // now lets send the email.
    ini_set("SMTP","smtp.gmail.com");
    ini_set("smtp_port","465");
    mail($to, $subject, $message, $headers);

    echo "Message has been sent....!";
?>

我遇到以下错误:

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

致命错误:C:\xampp\htdocs\testMail.php 第 33 行的最大执行时间超过 30 秒

【问题讨论】:

  • 据我所知,Google 的 SMTP 服务器需要身份验证以及使用加密 (SSL/TLS) 连接。您不能只指向带有 2 或 3 个标头的 smtp.gmail.com 并发送电子邮件。
  • 谢谢你们,我刚接触 php 可以说只是第一天,所以尝试 diff 的东西 thnaks 为你的指导

标签: php


【解决方案1】:

有时,ISP 会在一定程度上为其客户提供免费的 smtp 服务。 google yourisp & smtp。

【讨论】:

    【解决方案2】:

    您需要使用 SMTP 授权,才能使 gmail 的 SMTP 服务器正常工作,而邮件无法做到这一点。

    看看 PHPMailer,他们有一个很好的例子 here

    【讨论】:

      【解决方案3】:

      Gmail 服务器使用 TLS 和登录名/密码验证,您不能将它们与 PHP 的 mail() 函数一起使用。

      尝试使用Swiftmailer 之类的邮件库。下面是一个可能适用于 Gmail 的示例:http://swiftmailer.org/wikidocs/v3/connections/smtp

      【讨论】:

        猜你喜欢
        • 2015-10-01
        • 1970-01-01
        • 2015-08-22
        • 1970-01-01
        • 2015-05-11
        • 2013-07-21
        • 1970-01-01
        • 1970-01-01
        • 2016-05-10
        相关资源
        最近更新 更多