Home of a med student who likes to manage websites and talk tech!

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

with 5 comments

WordPress LogoIn 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.

  1. 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.
  2. Search for the following line.
    ; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
    sendmail_path = "/usr/sbin/sendmail -t -i"
  3. 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"
  4. 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’?

  1. Locate the pluggable.php file within the wp-includes directory where WordPress is installed.
  2. Open the file in a simple text editor. The 2 modifications that need to be made should begin on lines 351 and 362 respectively.
  3. 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';
  4. 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.
    if ( !isset( $from_email ) ) {
    		// Get the site domain and get rid of www.
    		$sitename = strtolower( $_SERVER['SERVER_NAME'] );
    		if ( substr( $sitename, 0, 4 ) == 'www.' ) {
    			$sitename = substr( $sitename, 4 );
    		$from_email = 'wordpress@' . $sitename;
  5. Save and update the pluggable.php file on the server.

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.

Thanks for reading and I hope you have found this HOW-TO useful.


Written by falcon1986

16 April, 2010 at 8:20 PM

Posted in Wordpress

Tagged with , ,

5 Responses

Subscribe to comments with RSS.

  1. in my website, this script not running on add on domain, why?

    doni tiaka

    10 June, 2010 at 1:53 AM

    • Do you have a separate php.ini file in your addon domain’s root web directory? You should.


      10 June, 2010 at 10:21 PM

  2. Hostmonster keeps showing my account and not the -fusername@domain.tld.


    a person

    12 June, 2010 at 4:47 PM

    • 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.


      13 June, 2010 at 11:39 AM

  3. This a is much simpler and straightforward solution:

    Just add this code block to your theme’s functions.php

    /* Changing email sender
    ======================================== */
    function defineSender(){
    $from_name = $sitename = strtolower( $_SERVER[‘SERVER_NAME’] );
    return $from_name;


    MAC 🙂


    22 September, 2011 at 12:29 PM

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: