WordPress Not Sending Mail After Moving Site to a New Server
There could be a couple issues causing WordPress to not send mail however in a server move the most likely is that the previous server was using Sendmail and the new server is using a different mail server like Postfix or vice versa. There also are a couple ways to resolve the issue and I will explain each method below however I recommend installing a WordPress Add-on to resolve the issue versus modifying a core WordPress file that could inadvertently be overwritten in the future.
The two ways which are described in detail to resolve this issue are to either install the WP-Mail-SMTP WordPress plugin or to modify the pluggable.php file located in the /wp-root/wp-includes directory. Each method will change the way that the $phpmailer function sends mail.
**NOTE** Modifying pluggable.php is not the recommended solution and is here to simply provide more than one option.
- Open pluggable.php:First locate and open pluggable.php in your favorite editor such as vi which is my favorite editor. The file is located in the wp-includes directory that is located in the root of your WordPress installation so use something like the below command from the root of your WordPress install to open and start editing the file. Remember to always backup a file before you begin editing it.
cp -p wp-includes/pluggable.php wp-includes/pluggable.php.orig vi wp-includes/pluggable.php
- Modify Line #381: Replace line #381 in the pluggable.php file from “$phpmailer->IsMail();” to “$phpmailer->IsSMTP();”. Once this has been replaced save the file.
- Test & Verify:Now check to see if mail is being sent from WordPress. This can be done numerous ways which I assume you know the way WP was not sending mail if you are reading this article. An example might be leaving a comment to a post.
Install WP-Mail-SMTP WordPress Plugin:
- WordPress Admin:Login to the admin portion of your WordPress site which is http://yourdomain.com/wp-admin by default.
- Expand Plugins:Click the arrow to the right of Plugins in the left navigation menu to expand the options below which include Installed, Add New, Editor, and Akismet Configuration.
- Locate WP-Mail-SMTP Plugin:Now click the Add New link to being the process of adding WP-Mail-SMTP. Type “wp-mail-smtp” in the search field near the top of the center column and then click the Search button. WP-Mail-SMTP should display at the top of the search results.
- Install WP-Mail-SMTP: Click Install under the Actions column of WP-Mail-SMTP. Follow the directions to complete the installation process.
- Activate WP-Mail-SMTP:Now activate the plugin by clicking on Installed underneath the Plugins section of the left navigation. Location WP-Mail-SMTP in the list and activate it.
- Configure WP-Mail-SMTP: Once activated there will be a new section under the Settings section of the left navigation menu called Email. Click on that settings link to launch the WP-Mail-SMTP configuration. For a quick test select the “Use PHP mail() function to send emails” radial button. Once selected click the Update Options button and then test WP sending email by using the “Send a Test Email” function at the bottom of the WP-Mail-SMTP configuration page. If you want to configure an external SMTP server do so now and then update the options.
Again my suggestion would be to make this change by adding the WP-Mail-SMTP plugin so in future upgrades you do not have to remember to modify the pluggable.php file. One way to see the details of the server sending mail is to view the /var/log/maillog file if you have access to do so on the server. This can point out other possible mail issues on the server.