Use the error in Phpmailer to resolve the "Connection failed. Error #2: Stream_socket_client (): SSL operation failed with code 1. OpenSSL Error messages: "

Source: Internet
Author: User
Tags php error ssl certificate



Phpmailer Project Address: Https://github.com/PHPMailer/PHPMailer



Phpmailer used in the project, the use of the process error: "Connection failed. Error #2: Stream_socket_client (): SSL operation failed with code 1. OpenSSL Error messages:"



Because the third-party SMTP I use is an SSL link, I need to add some more parameters:


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


This is the official explanation: "


This was covered in the troubleshooting docs. PHP 5.6 Verifies SSL certificates by default, and if your cert doesn ' t match, it'll fail with this error. The correct solution is to fix your SSL config-it ' s not PHP ' s fault!

If you're sending on the localhost you can use andisMail()it won ' t go through a encryption layer at all. "


Translate as follows:


This is described in the troubleshooting documentation. By default, PHP 5.6 validates the SSL certificate and this error occurs if your certificate does not match. The correct solution is to fix your SSL configuration-this is not a PHP error! If you are sending locally, you can use Ismail () instead of the encryption layer.





However, I use php7.1 Ah! As can be seen, PHP7 and above have retained the php5.6 feature. After adding the above parameters, the problem is solved.



However, the official suggestion is that, for the sake of safety, we recommend that you do the SSL certificate. For information on how PHP is tested for SSL certificates, please refer to: https://secure.php.net/manual/en/context.ssl.php






The method of validating the book in Phpmailer is given by the configuration:


 
$mail->SMTPOptions = array ( ‘ssl‘ => array( ‘verify_peer‘  => true,
        ‘verify_depth‘ => 3,
        ‘allow_self_signed‘ => true,
        ‘peer_name‘ => ‘smtp.example.com‘,
        ‘cafile‘ => ‘/etc/ssl/ca_cert.pem‘, )
);





Source: https://github.com/PHPMailer/PHPMailer/issues/368



Use the error in Phpmailer to resolve the "Connection failed. Error #2: Stream_socket_client (): SSL operation failed with code 1. OpenSSL Error messages: "


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.