首页 / PHP / 使用PHPMailer 中的报错解决 "Connection failed. Error #2: stream_socket_client(): SSL operation failed with code 1. OpenSSL Error messages:"
使用PHPMailer 中的报错解决 "Connection failed. Error #2: stream_socket_client(): SSL operation failed with code 1. OpenSSL Error messages:"
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了使用PHPMailer 中的报错解决 "Connection failed. Error #2: stream_socket_client(): SSL operation failed with code 1. OpenSSL Error messages:",小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1463字,纯文字阅读大概需要3分钟。
内容图文
PHPMailer项目地址:https://github.com/PHPMailer/PHPMailer
项目中用到PHPMailer,使用过程中报错:"Connection failed. Error #2: stream_socket_client(): SSL operation failed with code 1. OpenSSL Error messages:"
由于我用的第三方smtp是ssl链接,所以需要再添加一些参数:
$mail->SMTPOptions = array( ‘ssl‘ => array( ‘verify_peer‘ => false, ‘verify_peer_name‘ => false, ‘allow_self_signed‘ => true ) );
官方是这样说明的:"
This is covered in the troubleshooting docs. PHP 5.6 verifies SSL certificates by default, and if your cert doesn‘t match, it will fail with this error. The correct solution is to fix your SSL config - it‘s not PHP‘s fault!
If you‘re sending on localhost you can use
isMail()
and it won‘t go through an encryption layer at all."
翻译如下:
疑难解答文档中介绍了这一点。默认情况下,PHP 5.6验证SSL证书,如果您的证书不匹配,则会出现此错误。正确的解决方案是修复您的SSL配置 - 这不是PHP的错误! 如果您正在本地发送,您可以使用isMail(),而不会通过加密层。
可是,我用的是php7.1啊!可见,php7及以上版本保留了php5.6这一特点。加了上述参数后问题解决了。
不过,官方的建议是,为了安全起见,还是建议大家效验ssl证书的。关于PHP是如何效验ssl证书的,请参考:https://secure.php.net/manual/en/context.ssl.php
在PHPMailer里效验证书的方法,是有给出配置的:
$mail->SMTPOptions = array ( ‘ssl‘ => array( ‘verify_peer‘ => true, ‘verify_depth‘ => 3, ‘allow_self_signed‘ => true, ‘peer_name‘ => ‘smtp.example.com‘, ‘cafile‘ => ‘/etc/ssl/ca_cert.pem‘, ) );
出处:https://github.com/PHPMailer/PHPMailer/issues/368
原文:http://www.cnblogs.com/wpjamer/p/7421304.html
内容总结
以上是互联网集市为您收集整理的使用PHPMailer 中的报错解决 "Connection failed. Error #2: stream_socket_client(): SSL operation failed with code 1. OpenSSL Error messages:"全部内容,希望文章能够帮你解决使用PHPMailer 中的报错解决 "Connection failed. Error #2: stream_socket_client(): SSL operation failed with code 1. OpenSSL Error messages:"所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。