# 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.

- Type: PHP
- Runs: Run everywhere
- Category: [Email](https://wpide.com/library/category/email/)
- Tags: email, development, smtp
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/email-local-mailpit/

## Code

```php
$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 use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Catch All Email Locally With Mailpit or MailHog" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
