[英]SSL3_GET_SERVER_CERTIFICATE certificate verify failed on Windows 10 Pro with IIS
When trying to send emails through smtp.google.com
via PHPMailer on PHP hosted by IIS on Windows 10, I get this error message: 尝试在Windows 10上通过IIS托管的PHP通过PHPMailer通过
smtp.google.com
发送电子邮件时,出现以下错误消息:
Connection failed.
Error #2: stream_socket_enable_crypto(): SSL operation failed with code 1.
OpenSSL Error messages
error:14090086
SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
The key part of that error I'm sure is certificate verify failed . 我确定该错误的关键部分是证书验证失败 。 I'm running OpenSSL and it's enabled and linked to my php.
我正在运行OpenSSL,它已启用并链接到我的php。 Here is some info output by my local PHP instance:
这是我的本地PHP实例输出的一些信息:
OpenSSL support => enabled
OpenSSL Library Version => OpenSSL 1.0.1p 9 Jul 2015
OpenSSL Header Version => OpenSSL 1.0.1p 9 Jul 2015
Directive => Local Value => Master Value
openssl.cafile => no value => no value
openssl.capath => no value => no value
Here is my PHP code: 这是我的PHP代码:
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'src/Exception.php';
require 'src/PHPMailer.php';
require 'src/SMTP.php';
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 2; // 0 = off (for production use) - 1 = client messages - 2 = client and server messages
$mail->Host = "smtp.gmail.com"; // use $mail->Host = gethostbyname('smtp.gmail.com'); // if your network does not support SMTP over IPv6
$mail->Port = 587; // TLS only
$mail->SMTPSecure = 'tls'; // ssl is depracated
$mail->SMTPAuth = true;
$mail->Username = $smtpUsername;
$mail->Password = $smtpPassword;
$mail->setFrom($emailFrom, $emailFromName);
$mail->addAddress($emailTo, $emailToName);
$mail->Subject = 'PHPMailer GMail SMTP test';
$mail->msgHTML("test body"); //$mail->msgHTML(file_get_contents('contents.html'), __DIR__); //Read an HTML message body from an external file, convert referenced images to embedded,
$mail->AltBody = 'HTML messaging not supported';
// $mail->addAttachment('images/phpmailer_mini.png'); //Attach an image file
if(!$mail->send()){
echo "Mailer Error: " . $mail->ErrorInfo;
}else{
echo "Message sent!";
}
I'm out of my depth regarding OpenSSL and cert issues. 我对OpenSSL和证书问题不甚了解。 I have tried to understand the Updating CA certificates section of the PHPMailer troubleshooting guide , but I'm lost and confused.
我试图理解《 PHPMailer故障排除指南》中的“ 更新CA证书”部分,但我感到迷茫和困惑。 Can someone give me a set of steps I can follow and fix the cert problem on my local Windows 10 machine?
有人可以给我提供一些步骤,以便我可以在本地Windows 10计算机上执行并修复证书问题吗?
To paraphrase the guide, download the CA bundle from curl and store it somewhere on your file system. 要解释该指南,请从curl下载CA软件包并将其存储在文件系统中的某个位置。 Take the path you saved it to and add a line to your php.ini file saying:
采取将其保存到的路径,并在php.ini文件中添加一行,内容为:
openssl.cafile = $path
Where $path is where you saved the CA certs to. $ path是将CA证书保存到的位置。 Then restart your web server to pick up the ini change.
然后重新启动您的Web服务器以获取ini更改。
If that worked, you should see that setting in the output from phpinfo()
, and it should also give PHP what it needs to validate the certificate when PHPMailer uses it. 如果可行,您应该在
phpinfo()
的输出中看到该设置,并且还应该向PHP提供在PHPMailer使用证书时验证证书所需的内容。 Be aware that if the server is presenting a truly invalid or expired certificate, this won't help, but given that this a well-known problem and solution, I expect it to work. 请注意,如果服务器出示的证书真正无效或已过期,这将无济于事,但是鉴于这是众所周知的问题和解决方案,我希望它能够正常工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.