# Block All Outgoing Email on Staging Sites

> Stops WordPress from sending any email on development, local and staging environments, so test orders and imports never reach real people.

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

## Code

```php
add_filter( 'pre_wp_mail', function ( $return ) {
    if ( 'production' !== wp_get_environment_type() ) {
        return false;
    }

    return $return;
} );
```

## Notes

Set WP_ENVIRONMENT_TYPE in wp-config.php. Emails are silently dropped and wp_mail() returns false.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Block All Outgoing Email on Staging Sites" 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/
