PHPMailer身份验证失败

时间:2015-11-04 21:27:26

标签: php phpmailer

当我尝试在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

2 个答案:

答案 0 :(得分:0)

通过更改$ mail-> SMTPAuth = true解决问题;为假。

$ mail-> SMTPAuth = False;

答案 1 :(得分:0)

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