无法连接到GMail SMTP(PHPMailer) - 证书验证失败 [英] Cannot connect to GMail SMTP (PHPMailer) - Certificate Verify Failed

查看:342
本文介绍了无法连接到GMail SMTP(PHPMailer) - 证书验证失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 警告:stream_socket_enable_crypto():SSL操作代码1失败。
OpenSSL错误消息:错误:14090086:SSL例程:ssl3_get_server_certificate:证书验证失败,C:\xampp\htdocs\portal\libraries\php_mailer\class.smtp.php在线343
2017-12-05 09:48:03 SMTP错误:无法连接到SMTP主机。
2017-12-05 09:48:03客户 - > SERVER:QUIT
2017-12-05 09:48:03 SMTP错误:QUIT命令失败:

服务器地址为 https://gg-portal.com ,且SSL配置似乎正确(通过验证在线跳棋)。



PHPMailer代码是...

  $ mail = new PHPMailer(); 
$ mail-> isSMTP();
$ mail-> Host =smtp.gmail.com;
$ mail-> SMTPAuth = true;
$ mail->用户名= $ this-> _config [EmailUser];
$ mail->密码= $ 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'消息未被发送。';
echo'邮件错误:'。 $ MAIL-> ERRORINFO;
}

查看了证书问题的文档,精细。已经在其他地方调查过这个问题,最受欢迎的建议是绕过SSL(可行),但我不希望这样做。

 'context'=> [
'ssl'=> [
'verify_peer'=>假,
'verify_peer_name'=>假,
'allow_self_signed'=>真正的
]
]


解决方案

针对ME
的固定问题我通过下载更新后的根证书文件并将我的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


Very recently encountered this error when trying to send mail via SMTP and 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:

Server address is https://gg-portal.com, and SSL configuration seems correct (verified through online checkers).

PHPMailer code is...

$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;
}

Have looked at the documentation which suggests certificate issues, though as stated SSL setup seems fine. Have looked into the issue elsewhere and most popular suggestions is to bypass the SSL (which works) however I'd prefer not to do this.

'context' => [
    'ssl' => [
        'verify_peer' => false,
        'verify_peer_name' => false,
        'allow_self_signed' => true
    ]
]

解决方案

FIXED ISSUE FOR ME I fixed this issue in my windows php environment by downloading an updated root certificates file and pointing my php.ini file to it. It seems the problem was not with gmail's cert but rather with an outdated root certificate file due to windows server 2012 no longer updating this file automatically. Download cacert.pem from here: https://curl.haxx.se/docs/caextract.html. Then in php.ini use following line to point to it (assuming you have openssl.dll installed).

openssl.cafile={Path to the file on your server}\cacert.pem.

That fixed it and I no longer needed to bypass SSL/TLS verification like suggested. Ultimately I need to get windows to update root certs automatically using GPO or WSUS. see https://serverfault.com/questions/541922/where-to-get-root-ca-certificates-for-windows-server-now-that-microsoft-no-longe

这篇关于无法连接到GMail SMTP(PHPMailer) - 证书验证失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆