PHPMailer Encounters PHP Warning: Certificate Mismatch
Issue:
In PHP 5.6, PHPMailer encounters a PHP Warning indicating a certificate mismatch during TLS encryption:
PHP Warning: stream_socket_enable_crypto(): Peer certificate CN=*.mail.dreamhost.com' did not match expected CN=mx1.sub4.homie.mail.dreamhost.com'
Explanation:
From PHP 5.6 onwards, certificate verification is enabled by default for SSL connections. This means PHPMailer will compare the certificate presented by the SMTP server with the expected certificate. If there's a mismatch, the connection attempt may fail.
Resolution:
The recommended solution is to ensure that your SMTP server has a valid and properly configured certificate. Alternatively, you can configure PHPMailer to ignore certificate validation:
<code class="php">$mail->SMTPOptions = array ( 'ssl' => array( 'verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true));</code>
Additional Considerations:
The above is the detailed content of Here are some potential titles, combining your article\'s information with a question format: Direct and Clear: * PHPMailer TLS Encryption: Why am I getting a Certificate Mismatch Warning? * Certifi. For more information, please follow other related articles on the PHP Chinese website!