【问题标题】:PHPMailer wont send mailsPHPMailer 不会发送邮件
【发布时间】:2013-12-15 15:05:02
【问题描述】:

我有这个 PHPMailer:https://github.com/PHPMailer/PHPMailer/

我的代码是这样的:

    $mail = new PHPMailer;

    $mail->isSMTP();                                      // Set mailer to use SMTP
    $mail->Host = 'kms-play.it';  // Specify main and backup server
    $mail->SMTPAuth = true;                               // Enable SMTP authentication
    $mail->Username = 'noreply@kms-play.it';                            // SMTP username
    $mail->Password = 'pass';                           // SMTP password
    $mail->SMTPSecure = 'tls';                            // Enable encryption, 'ssl' also accepted

    $mail->From = 'noreply@kms-play.it';
    $mail->FromName = 'KMS-Play';
    $mail->addAddress('evolutio@kms-play.it', 'Lars Mehrhoff');  // Add a recipient

    #$mail->WordWrap = 50;                                 // Set word wrap to 50 characters
    #$mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments
    #$mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name
    #$mail->isHTML(true);                                  // Set email format to HTML

    $mail->Subject = 'Here is the subject';
    $mail->Body    = 'This is the HTML message body <b>in bold!</b>';
    $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

    if(!$mail->send()) {
       echo 'Message could not be sent.';
       echo 'Mailer Error: ' . $mail->ErrorInfo;
       exit;
    }
    echo 'Message has been sent';

错误是:

2013-12-15 15:02:23 客户端 -> 服务器:EHLO local.kms-play.it 2013-12-15 15:02:23 客户端 -> 服务器:STARTTLS 2013-12-15 15:02 :23 SMTP 错误:STARTTLS 命令失败:502 5.5.1 错误:命令未实施 2013-12-15 15:02:23 CLIENT -> SERVER: QUIT SMTP connect() 失败。无法发送邮件。Mailer 错误:SMTP 连接()失败。

【问题讨论】:

  • 您确定kms-play.it 支持TLS 连接?
  • 通过问题标题,我虽然 PHPMailer 宣布服务关闭。
  • 如果没有 TLS,它会说:2013-12-15 15:10:33 CLIENT -&gt; SERVER: EHLO local.kms-play.it 2013-12-15 15:10:33 CLIENT -&gt; SERVER: AUTH LOGIN 2013-12-15 15:10:33 SMTP ERROR: AUTH command failed: 535 5.7.8 Error: authentication failed: Invalid authentication mechanism 2013-12-15 15:10:33 CLIENT -&gt; SERVER: QUIT SMTP connect() failed. Message could not be sent.Mailer Error: SMTP connect() failed.
  • 使用test-smtp.com测试你的smtp服务器。
  • 我也想试试swiftmailer.org,你可能会做得更好。 PHPMailer 说它支持“使用 LOGIN、PLAIN、NTLM 和 CRAM-MD5 机制的 SMTP 身份验证”,但是在这种情况下,它似乎无法与服务器就 AUTH 机制达成一致。我希望它用不同的方法再尝试几次,但一次尝试就失败了。我也找不到任何方法来指定要使用的 AUTH 方法 - 所以你可以尝试它们,直到一个工作。

标签: php phpmailer


【解决方案1】:

你有两个选择:

1 - 由于TLS 不活跃,请评论此行:

$mail->SMTPSecure = 'tls';

不签名发送邮件也可以,但不好。

2 - 确保激活TLS 并且EHLO 命令应该返回:

EHLO myfriend
2016-10-27 01:15:07 SERVER -> CLIENT: 250-server.urutecno.net 
Hello mail.myfriemd.com [216.111.111.111]
250-SIZE 52428800
250-8BITMIME
250-PIPELINING
250-AUTH PLAIN LOGIN
250-STARTTLS
250 HELP

【讨论】:

    【解决方案2】:

    只是配置问题。

    更新 转到网页 ::https://github.com/PHPMailer/PHPMailer/releases 获取 --> PHPMailer-5.2-stable 并浏览到示例\mailing_list.phps

    将以下配置文件添加到文件中,它会开箱即用。

         $mail->SMTPOptions = array(
                    'ssl' => array(
                        'verify_peer' => false,
                        'verify_peer_name' => false,
                        'allow_self_signed' => true
                    )
                );
        $mail->isSMTP();
        $mail->SMTPAutoTLS = false;
        $mail->Port = 587;
        $mail->SMTPAuth = true;
          $mail->SMTPSecure = 'tls';
    

    肯定会成功的

    【讨论】:

    • 此配置将关闭对呈现给您的 PHP 应用程序的 TLS 证书的所有验证。如果有人试图干预您的 SMTP 连接,您将永远不会知道。
    【解决方案3】:

    我猜这可能是错误的:

    $mail->Host = 'kms-play.it'; 
    

    那真的是您的 SMTP 主机吗?通常它类似于 smtp.kms-play.it。最好咨询您的托管服务提供商。

    【讨论】:

    • 是的,雷鸟设置与脚本中的相同。我在服务器上的 mail.err/.info 或 mail.log 中没有发现任何错误
    • 正在建立连接,服务器甚至响应:“502 5.5.1 Error: command not implemented”(编辑:过早提交)
    猜你喜欢
    • 2012-09-15
    • 1970-01-01
    • 1970-01-01
    • 2013-10-05
    • 2013-09-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-24
    相关资源
    最近更新 更多