天天看點

phpmailer發送郵件出現錯誤:stream_socket_enable_crypto(): SSL operation failed with code 1.

如果開了調試,調試進去會看到錯誤提示:

smtp_code:"stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages:\nerror:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed"  

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

原因是升到php5.6後預設開啟驗證

添加參數,去掉驗證:

$mail->SMTPOptions = array(  

    'ssl' => array(  

        'verify_peer' => false,  

        'verify_peer_name' => false,  

        'allow_self_signed' => true,  

    )  

)  

參考文檔:

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:

<a href="http://www.devdungeon.com/content/how-use-ssl-sockets-php" target="_blank">http://www.devdungeon.com/content/how-use-ssl-sockets-php</a>

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' =&gt; [

'local_cert'        =&gt; '/path/to/key.pem',

'peer_fingerprint'  =&gt; openssl_x509_fingerprint(file_get_contents('/path/to/key.crt')),

'verify_peer'       =&gt; false,

'verify_peer_name'  =&gt; false,

'allow_self_signed' =&gt; true,

'verify_depth'      =&gt; 0 ]]);

$fp = stream_socket_client('ssl://ssl.server.com:12345',

   $errno, $errstr, 30, STREAM_CLIENT_CONNECT, $stream_context);

fwrite($fp, "foo bar\n");

while($line = fgets($fp, 8192)) echo $line;

如何聯系我:【萬裡虎】www.bravetiger.cn

【QQ】3396726884 (咨詢問題100元起,幫助解決問題500元起)

【部落格】http://www.cnblogs.com/kenshinobiy/