Preventing WordPress from Sending emails

Well, I was looking for a way to create new sites for existing users without sending out notification emails. I did manage to find one solution, but it's fairly drastic and should be used sparingly (and probably when you have scheduled maintenance if you have an active site). If you add the following code to wp-config.php, it will stop WordPress from sending outgoing emails (n.b., this means all outgoing emails):

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

Remember to remove this code when you are finished with your back-end work.

Like I said, this is a drastic solution, as it will stop your WordPress install from sending any outgoing email (e.g., password reminders), but it is useful if you have to do something in the back end that would generate hundreds or thousands of emails and you'd rather not spam your users (e.g., I used it to add a thousand sites to one of my installs without sending notifications to each of the thousand users involved).

  • aecnu
    • WP Unicorn

    Greetings Zyniker,

    Thank you for that great input and taking he time to post this code.

    One must also remember that this will only work if one is NOT using an SMTP plugin that already bypasses the wp_mail() function. In this case deactivate the SMTP plugin and use the code as advised.

    Cheers, Joe

  • Zyniker
    • WordPress Warrior

    Good call, Joe. That thought hadn't even crossed my mind since the SMTP plugin I use on my sites is setup on a per-site basis instead of for the entire network, so it didn't even come into play.

    As always, a test run of just a few users (or a number of your own email accounts, as is my own preference) is advisable before clicking "process" on any major Batch Create or other queue which could send hundreds or thousands of emails.

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.