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

使用PHPMailer 中的报错解决 "Connection failed. Error #2: stream_socket_client(): SSL operation failed with code 1. OpenSSL Error messages:"的更多相关文章

  1. web.xml配置文件中async-supported报错解决

    项目中配置spring时async-supported报错: 是因为<async-supported>true</async-supported>是web.xml 3.0的新特 ...

  2. nginx 使用HTTPS协议-SSL证书模块报错解决-附nginx安装 : [emerg] the "ssl" parameter requires ngx_http_ssl_module in nginx.c

    Linux系统下ngnix使用HTTPS协议启动报错: nginx: [emerg] the "ssl" parameter requires ngx_http_ssl_modul ...

  3. eclipse中SVN报错解决

    在Eclipse市场上安装完SVN插件后连接SVN时出现以下错误: SVN: '0x00400006: Validate Repository Location' operation finished ...

  4. Android开发过程中部分报错解决方法。

    初学Android,最近在使用zxing开发一个条码扫描解析的安卓项目中,遇到以下几个问题.贴出来以供参考. 1.Http请求错误    Android4.0以上要求不能把网络请求的操作放在主线程里操 ...

  5. Mysql8.0中caching_sha2_password报错解决

    https://blog.csdn.net/litte_frog/article/details/80874105

  6. Aasible中cryptography兼容性报错解决办法

    Aasible中cryptography兼容性报错解决办法 1 Ansible中使用ansible --version查看版本,报错信息如下: ERROR! Unexpected Exception, ...

  7. MyEclipse中jsp的凝视报错解决

    jsp页面中凝视报错: 出错现场:在eclipse中没有报错.在MyEclipse中报错. <!-- To use express install, set to playerProductIn ...

  8. vuex中的babel编译mapGetters/mapActions报错解决方法

    vex使用...mapActions报错解决办法 vuex2增加了mapGetters和mapActions的方法,借助stage2的Object Rest Operator 所在通过 methods ...

  9. redis运用连接池报错解决

    redis使用连接池报错解决redis使用十几小时就一直报异常 redis.clients.jedis.exceptions.JedisConnectionException: Could not g ...

随机推荐

  1. Create JSON by Jackson API(转)

      原文地址: Create JSON by Jackson API Jackson API is a multi-purpose Java library for processing JSON. ...

  2. button disable and enable

    1. disable <button id="buttonId" disabled>......</button> $("#buttonId&qu ...

  3. 在vue项目中使用sass

    如果想开发移动端项目,那么适配的时候sass必不可缺,但是 npm  安装sass时候总是报错失败! 研究半天发现可以解决的方法,亲测有效 1.先换成淘宝镜像再安装 npm install -g cn ...

  4. office install problems

    regedit 0000 "00005"或"00002"开头的项 remove all regedit options

  5. ubuntu下的网速限制软件wondershaper (2011-09-18 00:00:00)转载▼

    上网或下载的时候我们常常希望网速快一点,但有时我们也需要限制网速,在ubuntu系统下,可以使用wondershaper,不仅可以限制下载速度还可以限制上传速度. 安装好之后,需要使用终端取得管理员权 ...

  6. PHP7 ci框架session存文件,登录的时候session不能读取

    config.php配置 $config['sess_driver'] = 'files';//以文件存储session $config['sess_cookie_name'] = 'ci_sessi ...

  7. shell shell基本概述

    SHELL的概念 SHELL是一个命令行解释器,它为用户提供了一个向Linux内核发送请求以便运行程序的界面系统级程序, 用户可以用shell来启动,挂起,停止甚至是编写一些程序. ​ Shell还是 ...

  8. Daily record-June

    June201. Dear, wake up! Seven o'clock now, it's time to get up. Wash your face and to have breakfast ...

  9. QuickStart系列:docker部署之PostgreSQL

    mysql --> mariadb --> postgresql 官网简介 https://www.postgresql.org/ 使用的镜像名称 centos/postgresql-96 ...

  10. global 全局变量 nonlocal 局部变量

    # x= # def func(): # x= # # func() # print(x) # x=[] # def func(): # x.append() # x.append() # x.app ...