Catch All Email Locally With Mailpit or MailHog
On local and development sites, sends every WordPress email to a local mail catcher such as Mailpit, MailHog or the one built into Herd, Local or DDEV, so nothing reaches real inboxes.
Opens WPIDE on
Code
$wpide_catcher_host = '127.0.0.1';
$wpide_catcher_port = 1025;
add_action( 'phpmailer_init', function ( $phpmailer ) use ( $wpide_catcher_host, $wpide_catcher_port ) {
if ( ! in_array( wp_get_environment_type(), array( 'local', 'development' ), true ) ) {
return;
}
$phpmailer->isSMTP();
$phpmailer->Host = $wpide_catcher_host;
$phpmailer->Port = $wpide_catcher_port;
$phpmailer->SMTPAuth = false;
$phpmailer->SMTPSecure = '';
$phpmailer->SMTPAutoTLS = false;
}, 999 );
Notes
Only active when WP_ENVIRONMENT_TYPE is local or development; change the host and port to match your tool (Mailpit and MailHog use port 1025).
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.