How to disable the sending of email messages in WordPress - Disable wp_mail() function

Providing a valid email address is a mandatory step in the installation WordPress. On the email address of the admin user I come password reset messages, site health and messages then when visitors leave comments. For many reasons, however, you want to know how to disable the sending of email messages in WordPress. The main reason being spam messages or, even worse, the vulnerability of a plugin that exploits the function wp_mail() and sends spam messages to tens of thousands of addresses.

Most spam messages from WordPress are sent via PHPMailer when a form is vulnerable or when a plugin allows third-party PHP scripts to use wp_mail().

If you have a blog or a website on WordPress and it is not necessary for the system to send email messages to the administrator or users, then the best solution is to disable the email function of WordPress.

How to disable the sending of email messages in WordPress - Disable wp_mail() function
How to disable the sending of email messages in WordPress

Before following the steps in the tutorial below, remember that this method will completely disable your email system WordPress. Email messages will no longer be sent to reset the password, messages when the site encounters functionality problems or when users comment on the blog. If you use modules like Contact Form, set them not to send email messages via PHPMailer.

How to disable the sending of email messages in WordPress

This method does not require the installation of a plugin. All you have to do is edit the functions.php file of the active blog theme and add the following lines of code:

add_filter('pre_wp_mail', 'sth_disable_emails');
function sth_disable_emails() {
    return false;
}

Save the change. That's all.

Passionate about technology, I enjoy writing on StealthSettings.com since 2006. I have a rich experience in operating systems: macOS, Windows, and Linux, as well as in programming languages and blogging platforms (WordPress) and for online stores (WooCommerce, Magento, PrestaShop).

How to » WordPress » How to disable the sending of email messages in WordPress - Disable wp_mail() function
Leave a Comment