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

Susan Sarandon
Release: 2024-10-26 10:56:30
Original
478 people have browsed it

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.
Copy after login

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>
Copy after login

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!

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!