Skip to content

Instantly share code, notes, and snippets.

@bigdawggi
Last active June 3, 2019 19:11
Show Gist options
  • Save bigdawggi/6041493 to your computer and use it in GitHub Desktop.
Save bigdawggi/6041493 to your computer and use it in GitHub Desktop.
Mailtrap filter for WordPress
/**
* Routes all email from WP installation to specific Mailtrap
* account inbox.
*
* All you need to do is change the "Username" and "Password"
* settings to the appropriate box in Mailtrap. Then all
* mail **should** be routed to that box. Exceptions would
* be other functionality that overwrite the wp_mail() functions
* and may not use this filter, or other filters that change
* this behavior after we set it, or millions of other things.
*
* @param object $phpmailer - PHPMailer object (by reference)
*/
function use_mailtrap($phpmailer) {
$phpmailer->IsSMTP();
$phpmailer->SMTPAuth = true;
$phpmailer->Host = "mailtrap.io";
$phpmailer->Port = 2525;
$phpmailer->Username = "";
$phpmailer->Password = "";
}
add_action( 'phpmailer_init', 'use_mailtrap' );
@eduardo-marcolino
Copy link

I've wrapped it into a plugin:
https://wordpress.org/plugins/mailtrap-for-wp/

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