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: "