Her*_*der 1 php iis phpmailer php-openssl
当尝试smtp.google.com通过PHPMailer在Windows 10上由IIS托管的PHP上发送电子邮件时,我收到以下错误消息:
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
Run Code Online (Sandbox Code Playgroud)
我确定该错误的关键部分是证书验证失败.我正在运行OpenSSL,它已启用并链接到我的PHP.这是我的本地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
Run Code Online (Sandbox Code Playgroud)
这是我的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!";
}
Run Code Online (Sandbox Code Playgroud)
我对OpenSSL和证书问题不太了解.我试图理解PHPMailer故障排除指南中的更新CA证书部分,但我迷失了方向.有人可以给我一套我可以遵循的步骤并在我的本地Windows 10机器上修复证书问题吗?
要解释该指南,请从curl下载CA捆绑包并将其存储在文件系统上的某个位置.把你保存的路径拿到并在你的php.ini文件中添加一行说:
openssl.cafile = $path
Run Code Online (Sandbox Code Playgroud)
其中$ path是您保存CA证书的位置.然后重新启动Web服务器以获取ini更改.
如果这样可行,您应该在输出中看到该设置phpinfo(),并且它还应该给PHP在PHPMailer使用它时验证证书所需的内容.请注意,如果服务器正在呈现一个真正的无效或过期的证书,这不会帮助,但考虑到这是一个众所周知的问题和解决方案,我期望它的工作.
| 归档时间: |
|
| 查看次数: |
4948 次 |
| 最近记录: |