Home > Article > Backend Development > Why Does PHPMailer Generate a \"stream_socket_enable_crypto(): Peer Certificate Mismatch\" Warning and How Can I Fix It?
PHPMailer Generates Warning: stream_socket_enable_crypto(): Peer Certificate Mismatch
The enhanced security measures implemented in PHP 5.6 have impacted the use of PHPMailer. When attempting to send messages to certain domains, such as those hosted by Dreamhost, users may encounter an error: "Could not connect to SMTP host."
Further investigation reveals an underlying issue with certificate validation. PHPMailer logs "PHP Warning: stream_socket_enable_crypto(): Peer certificate CN=*.mail.dreamhost.com' did not match expected CN=mx1.sub4.homie.mail.dreamhost.com'."
To resolve this issue, it is crucial to understand that certificate verification is not optional and ignoring it compromises security. The correct solution, as stated in the PHPMailer documentation, is to replace the invalid or misconfigured certificate with a valid one.
If certificate validation remains non-negotiable but message delivery is still necessary, it is possible to bypass verification temporarily. This can be achieved by setting the following SMTPOptions:
$mail->SMTPOptions = array( 'ssl' => array( 'verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true ) );
However, this approach should be used with caution and is only recommended as a temporary measure until proper certificate configuration can be addressed.
The above is the detailed content of Why Does PHPMailer Generate a \"stream_socket_enable_crypto(): Peer Certificate Mismatch\" Warning and How Can I Fix It?. For more information, please follow other related articles on the PHP Chinese website!