【问题标题】:Ho to resolve SMTP connect failed error如何解决 SMTP 连接失败错误
【发布时间】:2016-10-25 10:58:45
【问题描述】:

我正在尝试使用PHPMailer 发送带有 pdf 附件的邮件。

代码:

    include_once("./PHPMailer/PHPMailerAutoload.php");
    $mail = new PHPMailer(); // create a new object
    $mail->IsSMTP(); // enable SMTP
    $mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
    $mail->SMTPAuth = true; // authentication enabled
    $mail->SMTPSecure = 'tls'; // secure transfer enabled REQUIRED for Gmail
    $mail->Host = "smtp.gmail.com";
    $mail->Port = 587; // or 587
    $mail->IsHTML(true);
    $mail->Username = "username@gmail.com";
    $mail->Password = "accual password";
    $mail->SetFrom("test1@gmail.com");
    $mail->Subject = "Test";
    $mail->Body = "hello";
    $mail->AddAddress("test2@gmail.com");

    if (!$mail->Send()) {
        echo "Mailer Error: " . $mail->ErrorInfo;
    } else {
        echo "Message has been sent";
    }

错误:

2016-10-25 10:40:27 CLIENT -> SERVER: EHLO test.something.com
2016-10-25 10:40:27 CLIENT -> SERVER: STARTTLS
2016-10-25 10:40:27 CLIENT -> SERVER: EHLO test.something.com
2016-10-25 10:40:27 CLIENT -> SERVER: AUTH LOGIN
2016-10-25 10:40:27 CLIENT -> SERVER: ... user name removed ... 
2016-10-25 10:40:27 CLIENT -> SERVER: ... password removed ...
2016-10-25 10:40:27 SMTP ERROR: Password command failed: 535-5.7.8 Username and Password not accepted. Learn more at 535 5.7.8 https://support.google.com/mail/?p=BadCredentials cy7sm4615595wjc.26 - gsmtp
2016-10-25 10:40:27 SMTP Error: Could not authenticate.
2016-10-25 10:40:27 CLIENT -> SERVER: QUIT
2016-10-25 10:40:27 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshootingthanks

我该如何解决这个问题?我感谢所有的回应。先谢谢了。

【问题讨论】:

标签: php phpmailer


【解决方案1】:

错误消息非常清楚地说明了(最有可能的)问题是什么:

不接受用户名和密码。

因此,请仔细检查用户名和密码是否正确,并且它们没有任何字符集问题。尝试快速搜索以找出 STMP 服务器期望的字符集类型,但找不到任何具体内容。

此外,您可能需要检查错误消息中包含的链接以及the gmail SMTP support page。更具体地说,这一点:

要使用 SSL 连接,您需要提供 Google 用户名和密码以进行身份​​验证。确保您使用的用户名已通过用户首次登录时出现的 CAPTCHA 字词验证测试。我们还建议确保该帐户具有安全密码。

【讨论】:

    【解决方案2】:

    请阅读您收到的错误消息。他们明确指出您的密码不正确。由于 SMTP 输出确实包含您的用户名和密码,所以我尝试登录并 gmail 报告您的密码不正确:

    请立即更改您的密码并在将错误消息添加到问题之前对其进行清理

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-04
    • 1970-01-01
    • 1970-01-01
    • 2016-07-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多