Home  >  Article  >  Backend Development  >  How to Fix \"Certificate Verify Failed\" Error When Using PHPMailer with a Self-Signed Certificate?

How to Fix \"Certificate Verify Failed\" Error When Using PHPMailer with a Self-Signed Certificate?

Susan Sarandon
Susan SarandonOriginal
2024-10-26 10:56:30479browse

How to Fix

PHPMailer SSL Verification Issue: Certificate Verify Failed

Problem:

When trying to send emails from a mail server with a self-signed certificate, PHPMailer throws the following error:

PHP Warning: stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages:
error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed in class.smtp.php on line 327.

Solution:

Starting with PHP 5.6, SSL certificate verification has been introduced. To revert to the old behavior without verification, set the SMTPOptions property in PHPMailer:

<code class="php">$mail->SMTPOptions = array(
    'ssl' => array(
        'verify_peer' => false,
        'verify_peer_name' => false,
        'allow_self_signed' => true
    )
);</code>

Note:

Disabling SSL verification has security implications. Without verification, malicious actors can impersonate trusted endpoints and perform Man-in-the-Middle Attacks. Consider these risks before using this solution.

The above is the detailed content of How to Fix \"Certificate Verify Failed\" Error When Using PHPMailer with a Self-Signed Certificate?. For more information, please follow other related articles on the PHP Chinese website!

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