email

Changing the Admin sending email address in WordPress

This problem has been racking my brain for months. I finally stumbled upon the solution in the wee hours of the night.

Here is the problem.

Whenever someone submits a comment, sign-up as a user or does anything that requires wordpress to generate an email, the “sent from” address does not reflect the users domain name. For example, with this issue the send from address is normally “rootuser@host#.hostname.com or wordpress@domain.com“. This is the default “sent from” address.

Super Simple Solution

Add this code into your functions.php file located in your theme files:

function res_fromemail($email) {
$wpfrom = get_option(‘admin_email’);
return $wpfrom;
}

function res_fromname($email){
$wpfrom = get_option(‘blogname’);
return $wpfrom;
}

add_filter(‘wp_mail_from’, ‘res_fromemail’);
add_filter(‘wp_mail_from_name’, ‘res_fromname’);

And thats it! If you dont like simple then use the solutions below

Solution #1 (This solution came from a reader and worked perfectly):

If  you use sender email as one of your domain emails, make sure you have either forwarder or mail box setup for that email. WordPress admin notifications is normally sent from wordpress@yourdomain.com and most of the time people don’t realize you have to actually make an email box or forwarder for wordpress@yourdomain.com that’s why when hostmonster checks your sender email and especially when you use yourdomain.com email and if it doesn’t exist, then hostmonster simply replace it with something like user34534@host456.hostmonster.com. Just make wordpress@yourdomain.com email or redeclare your own function wp_mail (original function can be found in wp-includes/pluggable.php) and replace $from_name = ‘WordPress’; and $from_email = ‘wordpress@’ . $sitename; with the name and email u wanna use. That’s it! Hope this helps, cause it’s annoying problem.

Example:

Replace ‘$from_name = ‘WordPress’’ With $from_name = ‘Admin

Replace $from_email = ‘wordpress@’ . $sitename; with $from_email = ‘admin@’ . $sitename;

Remember the new email MUST be created in your cPanel. This may be an actual mailbox or a forwarder.

Here’s a second solution (Recommend solution #1).

Edit this file: /includes/class-phpmailer.php

(Please make a backup of this file!)

Go to line 75 (wp version 2.8.2) and edit what is inside the quotes to reflect the email address you wish to use.

It may say something like “user@localhost”.

And on line 88, put your email address again inside the empty quotes.

Note: This email address should have already been created in your hosts cPanel. Examples of email addresses: donotreply@domainname.com or admin@domainname.com

Save the changes and upload the file to the wp-includes folder, overwriting the existing file (you should already have a backup of the file on your computer)

And thats it! You should now have emails from your wordpress blog coming from user@domain.

Another possible solution can be found here.

 

I am a mystery wrapped in a riddle, seen by all known by few, The one always apart in company yet never alone in solitude.

Leave a Reply

*

2 comments

  1. Thanks much. It would have worked perfectly if I’d made the second edit on line 88, but I only read that part after scouring the comments in the site you linked to. Silly me. Anyway, it works fine but there will be problems if the file is overwritten by an updated version of the file. Hopefully, it’s never updated. 😉

Next ArticleMy programs list aka the shit I use to get things done