PHP how to fix error: SSL routines:ssl3_get_server_certificate:certificate verify failed


When you receive this error:

OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed

You can fix by using context options with function stream_socket_client (you can replace old function fsockopen)

    $contextOptions=  array('ssl' => array (
        'verify_peer' => false,
        'verify_peer_name' => false,
        'allow_self_signed' => true)
    ) ;
    
    $context = stream_context_create($contextOptions);
 
    $this->smtp_conn = stream_socket_client("{$host}:{$port}", $errno, $errstr, $tval, STREAM_CLIENT_CONNECT, $context);

Old code:

    $this->smtp_conn = @fsockopen($host,     
                                 $port,     
                                 $errno,    
                                 $errstr,   
                                 $tval);     

Leave a Reply