PHPMailer 验证失败

3
当我在工作中使用Windows Server 2012上的PHPMailer通过SMTP发送报告电子邮件时,出现了身份验证失败的错误。
我正在使用域上的服务器管理员帐户。
我非常确定密码的正确性。
请检查下面的代码:
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

有正确的用户名和/或密码吗?我是说这似乎是要首先检查的事情。 - undefined
我建议重新检查$mail->SMTPSecure = 'tls';的配置,我认为首先尝试不带安全参数的方式,看看它的工作情况如何。通常,如果在托管环境中没有正确配置,安全的SMTP可能会引起问题。 - undefined
如果 STARTTLS 没有起作用,后续的 EHLO 也会失败,但事实并非如此,所以看起来你的加密工作正常。这似乎是一个简单的错误的 id/pass 问题。顺便说一下,那些认证字符串包含了你的 base64 编码的明文 id 和密码,所以如果我是你的话,我会将其编辑掉。 - undefined
没有成功,我尝试了3个账户,全部都显示密码错误。 - undefined
这个回答解决了你的问题吗?我能通过Office365共享邮箱发送SMTP邮件吗? - undefined
2个回答

1
通过将 $mail->SMTPAuth = true; 更改为 False,问题得到解决。 $mail->SMTPAuth = False;

1
!!!! 这是解决方案 !!!! 管理员一直删除我解决问题的方法:打开Microsoft 365管理中心,然后转到“用户”>“活动用户”。选择用户,在弹出的窗口中点击“邮件”。在“电子邮件应用程序”部分,点击“管理电子邮件应用程序”。验证“已认证的SMTP设置”:未选中=禁用,选中=启用。完成后,点击“保存更改”。 - undefined

0
如果您正在使用来自GoDaddy的Office 365并且已启用了2FA,请按照这些步骤禁用2FA。这解决了我的问题,即使SMTPAuthtrue也能正常工作。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接