Last active
March 18, 2025 16:48
-
-
Save slaFFik/c1d7d4249f47da7195fb973109952090 to your computer and use it in GitHub Desktop.
WP Mail SMTP: when using SMTP mailer - disable SSL verify on PHP 5.6+
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter('wp_mail_smtp_custom_options', function( $phpmailer ) { | |
$phpmailer->SMTPOptions = array( | |
'ssl' => array( | |
'verify_peer' => false, | |
'verify_peer_name' => false, | |
'allow_self_signed' => true | |
) | |
); | |
return $phpmailer; | |
} ); |
Thank you, it works! (using Wordpress 6.0 and WP Mail SMTP Version 3.2.1)
It works, thank you. For those wondering where to put this, the cleanest possible way is to use the Code Snippets plugin:
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you, it works!
I was having SMTP failure because my corporate SMTP server uses a self-signed certificate.
My first attempt was to edit WordPress core file
/wp-includes/PHPMailer/PHPMailer.php
with following class attribute values:public $SMTPOptions = [ 'ssl' => [ 'verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true ] ];
Although above solution worked, it triggered another issue: the plugin Wordfence complained "WordPress core file modified", which made sense to protect the WordPress core from being polluted.
So I kept search for better solution when I found this thread. I just added the codes into
/wp-content/themes/{my-theme-name}/functions.php
, and my WP Mail SMTP reported Email Test successfully.