Home  >  Article  >  Backend Development  >  How to Fix \"SSL3_GET_SERVER_CERTIFICATE: certificate verify failed\" Errors in PHPMailer?

How to Fix \"SSL3_GET_SERVER_CERTIFICATE: certificate verify failed\" Errors in PHPMailer?

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2024-10-26 09:49:30337browse

How to Fix

Troubleshoot SSL Certificate Verification Failures in PHPMailer

PHPMailer users may encounter "SSL3_GET_SERVER_CERTIFICATE: certificate verify failed" errors when sending emails from servers with self-signed certificates. This issue arises due to SSL certificate verification introduced in PHP 5.6.

Root Cause:

By default, PHPMailer verifies SSL certificates to ensure their authenticity. When a self-signed certificate is encountered, the verification fails due to the absence of an appropriate CA (Certificate Authority).

Solution:

To resolve this issue, you have two options:

1. Fix SSL Configuration:

If possible, obtain a valid SSL certificate that is signed by a trusted CA and install it correctly on your mail server. This will ensure successful certificate verification.

2. Disable SSL Certificate Verification (Not Recommended):

Warning: Disabling certificate verification has serious security implications. It exposes you to the risk of man-in-the-middle attacks.

To disable certificate verification, set the following PHPMailer options:

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

Editing the PHPMailer library to disable verification is highly discouraged as it will break upon upgrades.

Security Considerations:

Disabling SSL certificate verification should only be considered as a temporary workaround, not a long-term solution. It is crucial to secure your SSL configuration to prevent potential security breaches.

The above is the detailed content of How to Fix \"SSL3_GET_SERVER_CERTIFICATE: certificate verify failed\" Errors in PHPMailer?. 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