Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHPMailer - SSL3_GET_SERVER_CERTIFICATE:certificate verify failed

Have encountered an issue where email should be sent from an mail server which has self signed certificate, the error which I get is :

PHP 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 class.smtp.php on line 327. 

Has anyone encountered anything similar?

EDIT:

I have also tried to set the stream_context params (params: SSL context options):

$options['ssl']['verify_peer'] = false; $options['ssl']['verify_peer_name'] = false; $options['ssl']['allow_self_signed'] = true; 

No luck, it still fails with the same error as pointed above.

Thanks.

like image 337
gor181 Avatar asked Nov 09 '14 10:11

gor181


1 Answers

PHP 5.6 introduces SSL certificate verification, so if your config is broken, it will fail with this error. You should fix your SSL, but you can revert to the old behaviour by setting the SMTPOptions property to not verify certificates:

$mail->SMTPOptions = array(     'ssl' => array(         'verify_peer' => false,         'verify_peer_name' => false,         'allow_self_signed' => true     ) ); 

Editing the library defeats the entire point of libraries - and if you do as Kaf's answer suggests, your code will break when you upgrade. Really, don't do that.

Editor's note: disabling SSL verification has security implications. Without verification of the authenticity of SSL/HTTPS connections, a malicious attacker can impersonate a trusted endpoint (such as GitHub or some other remote Git host), and you'll be vulnerable to a Man-in-the-Middle Attack. Be sure you fully understand the security issues before using this as a solution.

like image 178
Synchro Avatar answered Oct 14 '22 02:10

Synchro