【发布时间】:2021-03-22 20:25:47
【问题描述】:
当我在工作中尝试在 windows server 2012 上使用 PHPMailer 使用 SMTP 发送报告电子邮件时,我收到了 Authentication unsuccessful 错误。
我在域上使用服务器管理员帐户。
我很确定密码的正确性。
检查下面的代码:
require '../PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 2;
$mail->Debugoutput = 'html';
$mail->Host = 'mail.example.com';
$mail->Port = 25;
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth = true;
$mail->Username = "username@example.com";
$mail->Password = "yourpassword";
$mail->setFrom('from@example.com', 'First Last');
$mail->addAddress('whoto@example.com', 'John Doe');
$mail->Subject = 'PHPMailer SMTP options test';
$mail->msgHTML($html_message);
我收到以下回复:
SERVER -> CLIENT: 220 exchangeserverhost.com Microsoft ESMTP MAIL Service ready at Tue, 3 Nov 2015 22:19:26 +0300
CLIENT -> SERVER: EHLO exchangeserverhost.com
SERVER -> CLIENT: 250-exchangeserverhost.com Hello
CLIENT -> SERVER: STARTTLS
SERVER -> CLIENT: 220 2.0.0 SMTP server ready
CLIENT -> SERVER: EHLO exchangeserverhost.com
SERVER -> CLIENT: 250-exchangeserverhost.com Hello
CLIENT -> SERVER: AUTH LOGIN
SERVER -> CLIENT: 334
CLIENT -> SERVER:
SERVER -> CLIENT: 334
CLIENT -> SERVER: ==
SERVER -> CLIENT: 535 5.7.3 Authentication unsuccessful
SMTP ERROR: Password command failed: 535 5.7.3 Authentication unsuccessful
SMTP Error: Could not authenticate.
CLIENT -> SERVER: QUIT
SERVER -> CLIENT: 221 2.0.0 Service closing transmission channel
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
【问题讨论】:
-
有正确的用户名和/或密码吗?我的意思是这似乎是要检查的第一件事。
-
我建议重新访问 $mail->SMTPSecure = 'tls'; 的配置我想先尝试不带安全参数,看看它是如何工作的。如果在主机上未正确配置,通常安全的 smtp 会导致问题。
-
如果 STARTTLS 不起作用,后续的 EHLO 也会失败,但事实并非如此,所以看起来您的加密工作正常。这看起来像是一个简单的错误 id/pass 问题。顺便说一句,这些身份验证字符串包括你的 base64 编码的纯文本 ID 和密码,所以如果我是你,我会编辑它。
-
没用,我试了3个账号都用相同的错误密码失败了。