Created
April 10, 2018 12:49
-
-
Save timotheemoulin/5ddb058d3bf10708aaaf5518f44df5b9 to your computer and use it in GitHub Desktop.
This file contains 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 | |
/* | |
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