Warning: stream_socket_enable_crypto(): SSL operation failed with code 1

Eugenijus picture Eugenijus · Nov 23, 2014 · Viewed 20.7k times · Source

I have a problem with CSCart, it fails sending mail via google account. To check if there is a problem in server config or in CSCart's scripts I installed clean library PHPMailer and tried to send test message using example script. Result is the same:

Warning: stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed in [script path]/class.smtp.php on line 338    

OpenSSL connection from console works good.

FreeBSD 10.0, Apache24, php5.6.

I could not find any information in google and for now I even do not know in which config file to search the issue root.

Answer

Synchro picture Synchro · Nov 25, 2014

This is due to the new verify-by-default policy in PHP 5.6. It's not set in php.ini; it's an option you an provide to fopen wrappers or stream contexts. Have a look at the options here, especially verify_peer. PHPMailer allows you to set these params during the smtpConnect() method, but there is no option to pass options into the smtpSend() method, so you will need to subclass PHPMailer to get at that.

You may find the alternative simpler - don't try to use a self-signed or unverifiable certificate.