今天在用搜狐提供的邮件群发系统的sdk,做发送邮件的测试时,提示:
last error : SSL certificate problem, verify that the CA cert is OK. Details: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
sdk代码如下:
1 1 <?php 2 2 send_mail(); 3 3 4 4 function send_mail() { 5 5 $ch = curl_init(); 6 6 7 7 curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); 8 8 curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); 9 9 10 10 curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); 11 11 curl_setopt($ch, CURLOPT_URL, 'https://sendcloud.sohu.com/webapi/mail.send.json'); 12 12 //不同于登录SendCloud站点的帐号,您需要登录后台创建发信子帐号,使用子帐号和密码才可以进行邮件的发送。 13 13 curl_setopt($ch, CURLOPT_POSTFIELDS, 14 14 array('api_user' => 'xxxx@xxx.org', 15 15 'api_key' => 'password', 16 16 'from' => 'xx@qq.com', 17 17 'fromname' => 'SendCloud团队', 18 18 'to' => 'lidongjun@huanqiu.com', 19 19 'subject' => 'php 调用WebAPI测试主题', 20 20 'html' => '欢迎使用<a href="https://sendcloud.sohu.com">SendCloud</a>', 21 21 //'file1' => '@/path/to/附件.png;filename=附件.png', 22 22 //'file2' => '@/path/to/附件2.txt;filename=附件2.txt' 23 23 )); 24 24 //设置对ssl不进行证书校验 25 25 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 26 26 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); 27 27 28 28 $result = curl_exec($ch); 29 29 30 30 if($result === false) //请求失败 31 31 { 32 32 echo 'last error : ' . curl_error($ch); 33 33 } 34 34 35 35 curl_close($ch); 36 36 37 37 return $result; 38 38 } 39 39 ?>
错误的提示时ssl验证不通过,解决办法
使用curl如果想发起的SSL请求正常的话有2种做法: 方法一、设定为不验证证书和host。 在执行curl_exec()之前。设置option $ch = curl_init(); ...... curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); 方法二、设定一个正确的证书。 本地ssl判别证书太旧,导致链接报错ssl证书不正确。 我们需要下载新的ssl 本地判别文件 http://curl.haxx.se/ca/cacert.pem 放到 程序文件目录 curl 增加下面的配置 curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,true); ; curl_setopt($ch,CURLOPT_CAINFO,dirname(__FILE__).'/cacert.pem');