首页 > 解决方案 > PHPMailer 突然发送失败

问题描述

我只是想问一下是否有解决方法。我的 phpmailer 设置工作正常,直到大约一周前发送失败。

这是我的 phpmailer 配置

$mail = new PHPMailer(true);
$mail->CharSet = "UTF-8";
$mail->isSMTP(); // Set mailer to use SMTP
$mail->SMTPDebug = 4; // Enable verbose debug output
$mail->Host = "smtp.office365.com"; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->SMTPKeepAlive = true; // SMTP connection will not close after each email sent, reduces SMTP overhead
$mail->Username = "email@email.com"; // SMTP username
$mail->Password = "secret"; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, ssl also accepted
$mail->Port = 587; // TCP port to connect to
$mail->SMTPOptions = array(
   'ssl' => array(
   'verify_peer' => false,
   'verify_peer_name' => false,
   'allow_self_signed' => true
   )
);

这是调试输出:

2021-10-28 08:38:24 Connection: opened
2021-10-28 08:38:24 SMTP INBOUND: "220 SJ0PR13CA0238.outlook.office365.com Microsoft ESMTP MAIL Service ready at Thu, 28 Oct 2021 08:38:24 +0000"
2021-10-28 08:38:24 SERVER -> CLIENT: 220 SJ0PR13CA0238.outlook.office365.com Microsoft ESMTP MAIL Service ready at Thu, 28 Oct 2021 08:38:24 +0000
2021-10-28 08:38:24 CLIENT -> SERVER: EHLO webapi.tanholdings.com
2021-10-28 08:38:25 SMTP INBOUND: "250-SJ0PR13CA0238.outlook.office365.com Hello [8.3.126.86]"
2021-10-28 08:38:25 SMTP INBOUND: "250-SIZE 157286400"
2021-10-28 08:38:25 SMTP INBOUND: "250-PIPELINING"
2021-10-28 08:38:25 SMTP INBOUND: "250-DSN"
2021-10-28 08:38:25 SMTP INBOUND: "250-ENHANCEDSTATUSCODES"
2021-10-28 08:38:25 SMTP INBOUND: "250-STARTTLS"
2021-10-28 08:38:25 SMTP INBOUND: "250-8BITMIME"
2021-10-28 08:38:25 SMTP INBOUND: "250-BINARYMIME"
2021-10-28 08:38:25 SMTP INBOUND: "250-CHUNKING"
2021-10-28 08:38:25 SMTP INBOUND: "250 SMTPUTF8"
2021-10-28 08:38:25 SERVER -> CLIENT: 250-SJ0PR13CA0238.outlook.office365.com Hello [8.3.126.86]250-SIZE 157286400250-PIPELINING250-DSN250-ENHANCEDSTATUSCODES250-STARTTLS250-8BITMIME250-BINARYMIME250-CHUNKING250 SMTPUTF8
2021-10-28 08:38:25 CLIENT -> SERVER: STARTTLS
2021-10-28 08:38:25 SMTP INBOUND: "220 2.0.0 SMTP server ready"
2021-10-28 08:38:25 SERVER -> CLIENT: 220 2.0.0 SMTP server ready
SMTP Error: Could not connect to SMTP host.
2021-10-28 08:38:25 SMTP NOTICE: EOF caught while checking if connected
2021-10-28 08:38:25 Connection: closed
SMTP Error: Could not connect to SMTP host.```

标签: phpemailoffice365phpmailertls1.2

解决方案


最近出现了一系列与 Outlook 相关的问题——我怀疑他们已经停止支持一些旧的 TLS 版本,并且只支持那些旧协议的旧 PHP 配置将停止工作。我认为他们正在他们的许多服务器上缓慢地推出这种变化,所以它会是间歇性的,但会越来越频繁地发生。

解决方案是更新您的 PHP 版本。


推荐阅读