【问题标题】:Cant connect to Office365 SMTP via PHPmailer无法通过 PHPmailer 连接到 Office365 SMTP
【发布时间】:2018-10-26 04:46:32
【问题描述】:

我无法通过 smtp 连接到 office365。我在这里阅读了所有提示,但没有任何帮助。

调试:

2018-05-16 08:12:52   Connection: opening to smtp.office365.com:587, timeout=300, options=array ( ) 
2018-05-16 08:12:52   Connection: opened 
2018-05-16 08:12:52   SERVER -> CLIENT: 220 CWLP265CA0229.outlook.office365.com Microsoft ESMTP MAIL Service ready at Wed, 16 May 2018 08:12:52 +0000 
2018-05-16 08:12:52   CLIENT -> SERVER: EHLO localhost 
2018-05-16 08:12:52   SERVER -> CLIENT: 250-CWLP265CA0229.outlook.office365.com Hello [109.81.243.32] 250-SIZE 157286400 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES 250-STARTTLS 250-8BITMIME 250-BINARYMIME 250-CHUNKING 250 SMTPUTF8 
2018-05-16 08:12:52   CLIENT -> SERVER: STARTTLS 
2018-05-16 08:12:52   SERVER -> CLIENT: 220 2.0.0 SMTP server ready 
2018-05-16 08:12:52   CLIENT -> SERVER: EHLO localhost 
2018-05-16 08:12:52   SERVER -> CLIENT: 250-CWLP265CA0229.outlook.office365.com Hello [109.81.243.32] 250-SIZE 157286400 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES 250-AUTH LOGIN XOAUTH2 250-8BITMIME 250-BINARYMIME 250-CHUNKING 250 SMTPUTF8 
2018-05-16 08:12:52   CLIENT -> SERVER: AUTH LOGIN 
2018-05-16 08:12:52   SERVER -> CLIENT: 334 VXNlcm5hbWU6 
2018-05-16 08:12:52   CLIENT -> SERVER: xxx== 
2018-05-16 08:12:52   SERVER -> CLIENT: 334 UGFzc3dvcmQ6 
2018-05-16 08:12:52   CLIENT -> SERVER: xxx= 
2018-05-16 08:12:58   SERVER -> CLIENT: 535 5.7.3 Authentication unsuccessful [CWLP265CA0229.GBRP265.PROD.OUTLOOK.COM] 
2018-05-16 08:12:58   SMTP ERROR: Password command failed: 535 5.7.3 Authentication unsuccessful [CWLP265CA0229.GBRP265.PROD.OUTLOOK.COM] 
2018-05-16 08:12:58   SMTP Error: Could not authenticate. 
2018-05-16 08:12:58   CLIENT -> SERVER: QUIT 
2018-05-16 08:12:58   SERVER -> CLIENT: 221 2.0.0 Service closing transmission channel 
2018-05-16 08:12:58   Connection: closed 
2018-05-16 08:12:58   SMTP connect() failed. 

PHP 代码:

$mail = new PHPMailer;
$mail->SMTPDebug = 3; 
$mail->isSMTP();
$mail->Host = 'smtp.office365.com'; 
$mail->SMTPAuth = true; 
$mail->Username = 'MAIL@DOMAIN.TLD'; 
$mail->Password = 'PASS';
$mail->SMTPSecure = 'tls';
$mail->Port = 587; // TCP port to connect to
$mail->setFrom('MAIL@DOMAIN.TLD');
$mail->addAddress('TOMAIL'); // Add a recipient
$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>';

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

【问题讨论】:

  • 这不是很有描述性吗? “密码命令失败:535 5.7.3 认证不成功”
  • 但是凭证没问题。这是怎么回事?
  • 显然不是。我刚刚用我的旧 hotmail 地址尝试了你的代码,它就像一个魅力。如果您 100% 确定凭据正确,那么您确定发件人地址托管在 Office365 上吗?
  • 是的。我刚刚使用此凭据登录到login.microsoftonline.com上的网络邮件@
  • 您也可以在 github 上查看 PHPMailer 的这个问题:github.com/PHPMailer/PHPMailer/issues/1339 - 好像 Office 365 的 SMTP 有点不稳定。

标签: php smtp office365 phpmailer


【解决方案1】:

您必须在 o365 管理面板中启用它,然后等待 3 分钟完成

同时检查 $mail->SMTPAuth = true;

使用 Microsoft 365 管理中心在特定邮箱上启用或禁用 SMTP AUTH

Open the Microsoft 365 admin center and go to Users > Active users.

Select the user, and in the flyout that appears, click Mail.

In the Email apps section, click Manage email apps.

Verify the Authenticated SMTP setting: unchecked = disabled, checked = enabled.

When you're finished, click Save changes.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-05-24
    • 2018-09-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多