PHPmailer未连接到office365 SMTP

PHPmailer未连接到office365 SMTP,php,smtp,phpmailer,Php,Smtp,Phpmailer,我有一个脚本,它使用phpmailer通过office 365 smtp发送电子邮件。它在过去一年左右一直在工作。现在连接到服务器时出错 PHP Fatal error: Uncaught PHPMailer\PHPMailer\Exception: SMTP Error: Could not connect to SMTP host. in C:\inetpub\wwwroot\Parishes_staging\ChristTheKing\vendor\phpmailer\phpmailer

我有一个脚本,它使用phpmailer通过office 365 smtp发送电子邮件。它在过去一年左右一直在工作。现在连接到服务器时出错

PHP Fatal error:  Uncaught PHPMailer\PHPMailer\Exception: SMTP Error: Could not connect to SMTP host. in C:\inetpub\wwwroot\Parishes_staging\ChristTheKing\vendor\phpmailer\phpmailer\src\PHPMailer.php:1898
Stack trace:
#0 C:\inetpub\wwwroot\Parishes_staging\ChristTheKing\vendor\phpmailer\phpmailer\src\PHPMailer.php(1725): PHPMailer\PHPMailer\PHPMailer->smtpConnect(Array)
#1 C:\inetpub\wwwroot\Parishes_staging\ChristTheKing\vendor\phpmailer\phpmailer\src\PHPMailer.php(1481): PHPMailer\PHPMailer\PHPMailer->smtpSend('Date: Fri, 14 F...', 'This is a multi...')
#2 C:\inetpub\wwwroot\Parishes_staging\ChristTheKing\vendor\phpmailer\phpmailer\src\PHPMailer.php(1320): PHPMailer\PHPMailer\PHPMailer->postSend()
#3 C:\inetpub\wwwroot\Parishes_staging\ChristTheKing\submitform2.php(195): PHPMailer\PHPMailer\PHPMailer->send()
#4 {main}
thrown in C:\inetpub\wwwroot\Parishes_staging\ChristTheKing\vendor\phpmailer\phpmailer\src\PHPMailer.php on line 1898
脚本如下:

require 'vendor/autoload.php';
$mail = new PHPMailer(true);
$mail->isSMTP();
$mail->Host = 'smtp.office365.com';
$mail->Port       = 587;
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth   = true;
$mail->Username = "user@company.org";                 
$mail->Password = "password";                           
$mail->SetFrom('sentfromemail@company.org', 'FromEmail');
//$mail->addAddress('user@company.org', 'ToEmail');
$mail->addAddress('user2@company.org', 'ToEmail');
$mail->addBCC('user2@company.org', 'ToBCCEmail');
$mail->SMTPDebug  = 3;
$mail->Debugoutput = function($str, $level) {echo "debug level $level; message: $str";}; 
$mail->Debugoutput = 'echo';
$mail->IsHTML(true);

$mail->Subject = 'Parish Registration Form';
$mail->Body    = $body;
$mail->AltBody = $body;

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

我在internet上搜索了与Office 365关联的连接设置,没有发现任何错误。Microsoft服务器上是否发生了我应该知道但没有发生的更改?

您这边没有任何问题


检查防火墙是否存在端口587阻塞。如果不是,则问题可能来自SMTP服务器端。请与Microsoft支持部门联系。

这是一个证书错误。如果php.ini中未指定证书文件,则应使用根证书。但它没有被使用

我必须添加以下代码才能使其正常工作:

$mail->SMTPOptions = array(
    'ssl' => array(
    'verify_peer' => false,
    'verify_peer_name' => false,
    'allow_self_signed' => true
    )
);

我检查过了,端口打开了。在联系微软之前,我还有什么可以尝试的吗?可能是测试服务器设置的一种方法。我认为您的服务器没有任何问题。我下载了SocketLabs SMTP控制台,如果使用相同的服务器、端口25且未加密,则能够连接和验证。我将代码中的端口更改为25,并且SMTPSecure='none';该页面刚刚超时,没有任何输出。您确定它正在连接到Office 365吗?我非常怀疑MS是否允许不加密的身份验证。服务器使用TLS加密,但使用smtp控制台时,我必须连接不加密,然后在身份验证之前建立连接后启动TTLS。这是否回答了您的问题?读一读。