尝试通过SMTP和GMail发送邮件时,最近遇到此错误。
Warning: stream_socket_enable_crypto(): SSL operation failed with code 1.
OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in C:\xampp\htdocs\portal\libraries\php_mailer\class.smtp.php on line 343
2017-12-05 09:48:03 SMTP Error: Could not connect to SMTP host.
2017-12-05 09:48:03 CLIENT -> SERVER: QUIT
2017-12-05 09:48:03 SMTP ERROR: QUIT command failed:
服务器地址为https://gg-portal.com,SSL配置似乎正确(通过在线检查程序验证)。
PHPMailer代码是......
$mail = new PHPMailer();
$mail->isSMTP();
$mail->Host = "smtp.gmail.com";
$mail->SMTPAuth = true;
$mail->Username = $this->_config["EmailUser"];
$mail->Password = $this->_config["EmailPass"];
$mail->SMTPSecure = "tls";
$mail->SMTPDebug = 1;
$mail->Port = 587;
$mail->FromName = $this->_config["Brand"];
$mail->From = $this->_config["EmailFrom"];
$mail->AddCC("...emailAddress...");
$mail->Subject = "...subject...";
$mail->Body = "...content...";
$mail->IsHTML(true);
$mail->WordWrap = 50;
if(!$mail->Send()) {
echo ' Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
}
已经查看了建议证书问题的文档,尽管如上所述SSL设置似乎没问题。已在其他地方研究过这个问题,最受欢迎的建议是绕过SSL(这有效),但我不想这样做。
'context' => [
'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
]
]
答案 0 :(得分:5)
我的固定问题 我通过下载更新的根证书文件并将我的php.ini文件指向它来修复我的Windows php环境中的这个问题。 似乎问题不在于gmail的证书,而在于由于Windows Server 2012不再自动更新此文件而导致过期的根证书文件。从这里下载cacert.pem:https://curl.haxx.se/docs/caextract.html。然后在php.ini中使用以下行指向它(假设您已安装openssl.dll)。
openssl.cafile = {服务器上文件的路径} \ cacert.pem。
修复了它,我不再需要像建议的那样绕过SSL / TLS验证。最终,我需要让Windows使用GPO或WSUS自动更新根证书。见https://serverfault.com/questions/541922/where-to-get-root-ca-certificates-for-windows-server-now-that-microsoft-no-longe