点证书不匹配“smtp.office354.com”使用PHPMailer的
问题描述:
美好的一天,点证书不匹配“smtp.office354.com”使用PHPMailer的
我有我的PHPMailer的SMTP配置错误时smtp.office365.com
这里我的脚本
require __DIR__ .'/vendor/phpmailer/phpmailer/src/Exception.php';
require __DIR__ .'/vendor/phpmailer/phpmailer/src/PHPMailer.php';
require __DIR__ .'/vendor/phpmailer/phpmailer/src/SMTP.php';
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
use PHPMailer\PHPMailer\SMTP;
$mail = new PHPMailer(true); // Passing `true` enables exceptions
try {
//Server settings
$mail->SMTPDebug = 4; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = gethostbyname('smtp.office365.com'); // Specify main and backup SMTP servers
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'office365 username'; // SMTP username
$mail->Password = 'office365 password'; // SMTP password
$mail->SMTPOptions = array (
'ssl' => array(
// 'verify_peer' => false,
// 'verify_peer_name' => false,
// 'allow_self_signed' => true
));
$mail->Port = 587; // TCP port to connect to
//Recipients
$mail->From = $mail->Username;
$mail->addAddress('[email protected]'); // Name is optional
//Attachments
//Content
$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>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
$mail->send();
echo 'Message has been sent';
} catch (Exception $e) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
}
我得到这个错误
stream_socket_enable_crypto(): Peer certificate CN=`servername.com' did not match expected CN=`smtp.office365.com'
如果我取消
$mail->SMTPOptions = array (
'ssl' => array(
// 'verify_peer' => false,
'peer_name' => 'smtp.office365.com',
// 'verify_peer_name' => false,
// 'allow_self_signed' => true
));
我仍然得到验证失败..
即时通讯服务器配置为别人做的服务器设置不是很好。但我的网站是在https上。
答
想想这是什么意思。您要求连接到指定的主机,但证书上的名称不匹配。这意味着服务器配置错误(对于office365不太可能),或者您被重定向到使用不同名称的其他服务器。这很可能,因为它在大型托管服务提供商中非常普遍。如果您将SMTPDebug = 2
设置为错误消息链接提供的故障排除指南,则会显示所有内容。
出现这种情况是好的事情 - 这是主要的原因使用TLS之一 - 它不仅加密在传输过程中您的流量,但提供了保证连接到服务器,你是一个你所料,即它正在做好自己的工作。
还一件事..它实际上是工作时,我的第一天配置,然后一个星期后,我再检查它,然后它开始产生这个错误..即时通讯真的不知道为什么.. – melvnberd
权 - 这意味着您的SMTP连接被截获并在其他地方重定向,因此名称不再匹配。这就是TLS正确地完成工作,防止中间人遭受攻击,并且停止向不知名的第三方颁发证书。检查你的ISP他们的出站SMTP策略。你可能*使用他们的服务器,如果你想使用地址的Gmail,这是个坏消息。 – Synchro
谢谢你的想法..也没有使用Gmail作为从,即时通讯实际上使用office365帐户..这是否会影响问题先生? – melvnberd