[HOW-TO] Modify WordPress’ admin e-mail address

In WordPress, you can set the e-mail address that the software uses whenever it needs to send user notifications for account activation, password retrieval, etc. However, for some reason, recipients might receive e-mails from a completely different-looking address or one where the header is read as ‘WordPress’. This obviously, looks a bit sloppy. You do not want to put doubt in your subscribers’ minds when they see an e-mail coming from an address that looks suspicious. This HOW-TO will show you what you need to modify in order to fix this little annoyance. It requires that you edit your php.ini file and the core WordPress file pluggable.php.

These procedures are intended for self-hosted installations of WordPress, since it is in these types of scenarios where the problem arises. They cannot be applied to WordPress blogs where you do not have read/write access to core WordPress files and the associated web directories.

When not configured properly, mail sent from some web hosts (e.g. HostMonster), appear as though they are coming from username@hostxyz.webhost.com or some variant. Why is it not coming from an e-mail address associated with your domain? First, you should ensure that the e-mail address that you instruct WordPress to use has been set up either locally or through a remote service. Once that is done you can proceed.

A. Edit php.ini

Editing php.ini will allow you to force the use of a specific e-mail address whenever WordPress wants to send an e-mail. It gets rid of the annoying username@hostxyz.webhost.com that some of your subscribers might see. This address should be the same that you specified through the WordPress settings.

Open the php.ini file associated with your website. If you do not see one in your website’s main directory you should have access to cPanel where ‘PHP Config’ can be used to automatically generate one. Ensure that the generated copy is (re)named php.ini. I tend to set ‘PHP Config’ to ‘Single PHP5′ so there is no need to place the php.ini in each and every directory where PHP scripts are being executed.

Modify the sendmail_path to something like this. Change username@domain.tld to suit your scenario. Note that there is no space between the -f flag and the e-mail address.

sendmail_path = "/usr/sbin/sendmail -t -i -fusername@domain.tld"

Save and update the php.ini file on the server with this modification.

B. Edit pluggable.php

You might be wondering why there is need to edit anything further since the above modification should have taken care of everything. To a degree, the above “fix” did, but you are not completely finished. Of course, this step is optional, but it fixes another case where you might encounter another annoyance. This annoyance is the ‘WordPress’ header which is associated with the admin e-mail address. For security reasons you might not want your subscribers to know outright that WordPress is powering your website, although it is not difficult to determine by other means. However, if we are using the username@domain.tld admin e-mail address, why not also have the e-mail header report that it is coming from domain.tld instead of ‘WordPress’?

Locate the pluggable.php file within the wp-includes directory where WordPress is installed.

Open the file in a simple text editor. The 2 modifications that need to be made should begin on lines 351 and 362 respectively.

Around line 351, change the ‘WordPress’ value of $from_name to the name you want to appear in the e-mail header. An appropriate value is your domain name. Maintain the enclosing single quotes.

// From email and name
// If we don't have a name from the input headers
if ( !isset( $from_name ) ) {
$from_name = 'WordPress';
}

Around line 362, change the ‘wordpress@’ value of $from_email to reflect the address that WordPress should use when sending admin e-mails. An appropriate value is username@ if you are using the generic example we started out with. Maintain the enclosing single quotes.

C. Plugins and conclusion

That’s all that you need to do. Hopefully, e-mails being sent by WordPress from now on should originate from the correct address. Obviously, the modification to pluggable.php is not a permanent fix because every time you update/upgrade WordPress it will be overwritten. Remember to reapply the modification after performing an update/upgrade.

The Mail From plugin for WordPress is supposed to take care of issues like this, but I have found that in certain cases it does not work. If you force WordPress to use SMTP to send e-mail you might not need to implement these fixes since the headers being issued by the SMTP mail server should already be correct.

On a completely unrelated note, I have found the WP Welcome Email Editor plugin to be excellent for customizing the content of subscriber activation e-mails being sent by WordPress.

For HostMonster: First of all, ensure that you have set the PHP Config within cPanel to PHP5 (Single PHP.INI) and apply the settings. This will generate a ‘php.ini.default’ file within your public_html directory. Rename it to php.ini and delete any old ones. Edit the sendmail path line in the new file.