PHPMailer-SSL3_GET_SERVER_CERTIFICATE:证书验证失败 [英] PHPMailer - SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
问题描述
遇到一个问题,应该从具有自签名证书的邮件服务器发送电子邮件,我得到的错误是:
Have encountered an issue where email should be sent from an mail server which has self signed certificate, the error which I get is :
PHP 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 class.smtp.php on line 327.
有人遇到过类似的事情吗?
Has anyone encountered anything similar?
我还尝试设置stream_context参数(参数: SSL上下文选项):
I have also tried to set the stream_context params (params: SSL context options):
$options['ssl']['verify_peer'] = false;
$options['ssl']['verify_peer_name'] = false;
$options['ssl']['allow_self_signed'] = true;
不走运,它仍然会失败,并出现与上述相同的错误.
No luck, it still fails with the same error as pointed above.
谢谢.
推荐答案
PHP 5.6引入了SSL证书验证,因此,如果您的配置被破坏,它将因该错误而失败.您应该修复SSL,但是可以通过将SMTPOptions
属性设置为不验证证书来恢复到旧的行为:
PHP 5.6 introduces SSL certificate verification, so if your config is broken, it will fail with this error. You should fix your SSL, but you can revert to the old behaviour by setting the SMTPOptions
property to not verify certificates:
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
编辑库会破坏整个库的作用-如果按照Kaf的回答建议进行操作,则升级时代码会中断.真的,不要那样做.
Editing the library defeats the entire point of libraries - and if you do as Kaf's answer suggests, your code will break when you upgrade. Really, don't do that.
编者注 :禁用SSL验证会产生安全隐患.如果不验证SSL/HTTPS连接的真实性,恶意攻击者可能会冒充受信任的端点(例如GitHub或其他远程Git主机),您将容易受到中间人攻击. 在将其用作解决方案之前,请确保您完全了解安全问题.
Editor's note: disabling SSL verification has security implications. Without verification of the authenticity of SSL/HTTPS connections, a malicious attacker can impersonate a trusted endpoint (such as GitHub or some other remote Git host), and you'll be vulnerable to a Man-in-the-Middle Attack. Be sure you fully understand the security issues before using this as a solution.
这篇关于PHPMailer-SSL3_GET_SERVER_CERTIFICATE:证书验证失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!