对等证书与使用phpmailer的“smtp.office354.com”不匹配
你好 我将phpmailer smtp配置为smtp.office365.com时出错 这是我的剧本对等证书与使用phpmailer的“smtp.office354.com”不匹配,php,email,server,certificate,phpmailer,Php,Email,Server,Certificate,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 P
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('recipient@gmail.com'); // 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;
}
如果我取消注释
$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的主要原因之一——它不仅可以加密传输过程中的流量,还可以确保您连接的服务器是您期望的服务器,即它正在正常工作。还有一件事。。当我第一天配置它时,它实际上正在工作,一周后,我检查它,然后它开始生成此错误。。我真的不知道为什么..对-这意味着你的SMTP连接被拦截并重定向到其他地方,因此名称不再匹配。这是TLS做正确的工作,防止中间人的攻击,并阻止你的证书被分发给一个未知的第三方。请向您的ISP咨询他们对出站SMTP的策略。你可能会被迫使用他们的服务器,如果你想使用Gmail发件人地址,这是个坏消息。。另外,我不是在使用gmail,我实际上是在使用office365帐户。。先生,这会影响问题吗?啊,对不起,我的错误,我指的是一个Office 365地址。我明白了。。谢谢,先生。。我会向ISP查询这个。。很高兴知道这不是由于我的代码而导致的错误:我也花了几天时间在这个问题上,我似乎无法匹配我的案例的所有其他答案。。我现在就继续讲下去,以防有其他建议
$mail->SMTPOptions = array (
'ssl' => array(
// 'verify_peer' => false,
'peer_name' => 'smtp.office365.com',
// 'verify_peer_name' => false,
// 'allow_self_signed' => true
));