Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save timotheemoulin/5ddb058d3bf10708aaaf5518f44df5b9 to your computer and use it in GitHub Desktop.
Save timotheemoulin/5ddb058d3bf10708aaaf5518f44df5b9 to your computer and use it in GitHub Desktop.
<?php
/*
Plugin Name: PHP Mailer Override
Version: 1.0.0
Description: Override config for development environment.
Author: Timothée Moulin
Author URI: https://timothee-moulin.me/
*/
defined( 'ABSPATH' ) OR exit;
if (WP_ENV === 'development' && !is_admin()) {
// Ensure that we are at the end of the queue to override any other SMTP configuration.
add_action('phpmailer_init', 'phpmailerdocker_init_smtp', 999);
}
/**
* Force the development SMTP configuration.
*
* @param PHPMailer $phpmailer
*/
function phpmailerdocker_init_smtp(PHPMailer $phpmailer)
{
// You can also store those values in your config file
$phpmailer->Host = 'smtp.whateveryouwant.com';
$phpmailer->Port = 25; // could be different
$phpmailer->SMTPAuth = false; // depends if you need to authenticate, if true, you must set the following values
// $phpmailer->Username = ''; // if required
// $phpmailer->Password = ''; // if required
// $phpmailer->SMTPSecure = 'ssl'; // 'ssl' enable if required, 'tls' is another possible value
// $phpmailer->SMTPOptions = array(
// 'ssl' => array(
// 'verify_peer' => false,
// 'verify_peer_name' => false,
// 'allow_self_signed' => true
// )
// );
// force using SMTP
$phpmailer->isSMTP();
// use a smaller timeout than default (300)
$phpmailer->Timeout = 4;
// print logs in your log file
$phpmailer->SMTPDebug = 4;
$phpmailer->Debugoutput = 'error_log';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment