Disable Emails Sending from WordPress in Development

May 3, 2018

Inevitably, there will be a time that you need to copy a live database to a local installation of WordPress to work on a new feature or fix a couple of bugs. Occasionally, these sites have user activity and require sending emails – like e-commerce transactional emails – to site users.

This is where copying a database to your computer gets tricky. You don’t want to send emails from your site to users twice – once from the live version and once from the development version. What you need to do is stop your local site from sending emails!

There are a couple of plugins that do this well (Stop Emails and Disable Emails), but you would have to then remember to enable these plugins whenever you copy your database locally. Not ideal.

The Code

Though this is a drastic approach, you can add the following snippet to your wp-config.php file to disable all wp_mail() based emails:

// Disable Outgoing WordPress Emails
function wp_mail() {
	//
}

Using a Plugin Still…

If you still really want to use a plugin for some reason, you can also add the following line to your wp-config.php to do the same by automatically activating the Stop Emails plugin (or your plugin of choice):

activate_plugin( 'stop-emails/stop-emails.php' );

Both methods guarantee that wp_email() triggered emails never leave your development site, though one doesn’t require an additional plugin to be installed.

NOTE: Make sure you don’t allow this to be enabled on your live site! This will keep people from even being able to request a password reset!

BONUS

Want to make sure that you know that wp_mail() is being disabled locally? Add this snippet to your wp-config.php as well to give yourself a notice in the backend that it’s enabled.

add_action( 'admin_notices', 'nomail_notice' );
function nomail_notice() {
    ?>
    <div class="error notice">
        <p><?php _e( '<strong>NO MAIL</strong> Mail from wp_mail() has been disabled for this site.', '' ); ?></p>
    </div>
    <?php
}

Wanna chat about this article or any others? Feel free to DM me or mention me on Twitter @marcusdburnette to start a conversation!

Browse topics

One more rabbit hole?

masthead-post2-18

March 14, 2026

Before You Add AI to WordPress, Build a Vendor-Exit Plan

As WordPress moves toward shared AI connectors and provider packages, site owners need one practical habit: choose tools you can leave without wrecking content or workflows.

Read article ↗

masthead-post2-8

February 26, 2026

7 non-dev habits that protect your WordPress site from XSS

XSS keeps showing up year after year. Here are seven practical, non-technical habits that shrink your WordPress risk without turning you into a security engineer.

Read article ↗