Skip to content

Instantly share code, notes, and snippets.

Last active January 23, 2024 18:35
Show Gist options
  • Save slaFFik/c1d7d4249f47da7195fb973109952090 to your computer and use it in GitHub Desktop.
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+
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;
} );
Copy link

slaFFik commented Jun 17, 2020

@Whateverinc Its definitely not secure. And users should fix there server setup to use a proper certificate.

Copy link

@slaFFik in my case, the client has been used this "unsecured" email server for a long time, and they don't even mind that issue as long as it works, and as a new developer for a new app, I must adapt

Copy link

hola yo tambien tengo problemas, no envia ni el correo de prueba (y ojo que estoy haciendo la prueba con un correo de gmail), me sale el sgte mensaje

No se pudo conectar con el host SMTP.

Esto significa que tu servidor web no pudo conectarse a

Normalmente, este error se devuelve por uno de los siguientes motivos:

-Los ajustes SMTP son incorrectos (puerto incorrecto, ajustes de seguridad, host incorrecto).
-Su servidor web está bloqueando la conexión.
-Tu host SMTP está rechazando la conexión.

si me pueden ayudar porfavor

Copy link

Thank you very much. Resolved the SSL related error and was able to send emails on my localhost setup.

Copy link

qwenmn commented Mar 27, 2021

where do i input this code or file location?

Copy link

where do i input this code or file location?

You can put any filter or action codes (hooks), including this code on the functions.php file located on your theme. And its recommended to use a child theme to avoid file replacement on theme updating process. About child theme:

Copy link

Thanks works like a charm!

Copy link

jinhr commented Jun 3, 2021

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.

Copy link

becahp commented Jun 20, 2022

Thank you, it works! (using Wordpress 6.0 and WP Mail SMTP Version 3.2.1)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment