phpmailer发送邮件出现错误:stream_socket_enable_crypto(): SSL operation failed with code 1.

摘要:
如果启用了调试,您将看到错误提示:[cpp]viewplaincopysmtp_code:“stream_socket_enable_crypto():SSL操作失败,代码为1。OpenSSL错误消息:错误:14090086:SSL例程:ssl3_get_server_certificate:certificateeverifyf

如果开了调试,调试进去会看到错误提示:

  1. smtp_code:"stream_socket_enable_crypto():SSLoperationfailedwithcode1.OpenSSLErrormessages: error:14090086:SSLroutines:ssl3_get_server_certificate:certificateverifyfailed"

最终提示是:Could not connect to SMTP host

原因是升到php5.6后默认开启验证

添加参数,去掉验证:

  1. $mail->SMTPOptions=array(
  2. 'ssl'=>array(
  3. 'verify_peer'=>false,
  4. 'verify_peer_name'=>false,
  5. 'allow_self_signed'=>true,
  6. )
  7. )

参考文档:

http://php.net/manual/en/context.ssl.php

去掉验证:

I am unable to load a PEM that was generated with the stunnel tools. However, I am able to use PHP calls to generate a working PEM that is recognized both by stunnel and php, as outlined here:
http://www.devdungeon.com/content/how-use-ssl-sockets-php
This code fragment is now working for me, and with stunnel verify=4, both sides confirm the fingerprint. Oddly, if "tls://" is set below, then TLSv1 is forced, but using "ssl://" allows TLSv1.2:
$stream_context = stream_context_create([ 'ssl' => [
'local_cert' => '/path/to/key.pem',
'peer_fingerprint' => openssl_x509_fingerprint(file_get_contents('/path/to/key.crt')),
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true,
'verify_depth' => 0 ]]);
$fp = stream_socket_client('ssl://ssl.server.com:12345',
$errno, $errstr, 30, STREAM_CLIENT_CONNECT, $stream_context);
fwrite($fp, "foo bar ");
while($line = fgets($fp, 8192)) echo $line;

http://php.net/manual/en/context.ssl.php

免责声明:文章转载自《phpmailer发送邮件出现错误:stream_socket_enable_crypto(): SSL operation failed with code 1.》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇XSS漏洞攻击原理与解决办法一、Linux 安装下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

PHPMailer邮件类使用错误分析

PHPMailer配置清单如下: require_once ‘class.phpmailer.php‘; $receiver = ”; $mail =newPHPMailer( ); $mail->IsSMTP(); $mail->IsHTML( true ); $mail->CharSet= “GB2312″; $mail->E...

利用PHPMailer 来完成PHP的邮件发送

1.首先是下载PHPMailer http://code.google.com/a/apache-extras.org/p/phpmailer/ 2.解压 从中取出class.phpmailer.php 和class.smtp.php 放到你的项目的文件夹,因为我们等下会引用到它们. 3.创建发送邮件的函数,其中你需要配置smtp服务器 function...