Why Does PHPMailer Throw a \'Peer Certificate Mismatch\' Error Under PHP 5.6?

Susan Sarandon
Release: 2024-10-27 06:23:29
Original
491 people have browsed it

 Why Does PHPMailer Throw a

PHPMailer Warning: Peer Certificate Mismatch

PHPMailer users encountering the "PHP Warning: stream_socket_enable_crypto(): Peer certificate did not match expected" error under PHP 5.6 may be facing issues with certificate validation.

Background:

PHP 5.6 introduced stricter certificate verification for SSL connections. As a result, if the remote server's SSL configuration is incorrect, PHPMailer will fail to encrypt the connection.

Symptoms:

  • Connection failure error: PHPMailer displays "Could not connect to SMTP host."
  • Logging error: The log shows a certificate mismatch warning: "Peer certificate CN=*.mail.dreamhost.com...' did not match expected CN=mx1.sub4.homie.mail.dreamhost.com...'".
  • Immediate QUIT command: PHPMailer may issue a QUIT command after attempting STARTTLS, indicating an encryption failure.

Solution:

The recommended solution is to correct the certificate or verification settings on the remote server. This may involve replacing an invalid certificate with a valid one or reconfiguring the SSL settings.

Alternative:

If immediate delivery is necessary and the certificate mismatch is not critical, you can disable certificate validation in PHPMailer using the following options:

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

Note: Disabling certificate validation is not recommended as it compromises security by potentially accepting invalid certificates.

The above is the detailed content of Why Does PHPMailer Throw a \'Peer Certificate Mismatch\' Error Under PHP 5.6?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!