Change WordPress FROM: (name and email address)

While setting up and testing WordPress, I realized the site’s users would all get email from someone named “wordpress” using the email address “wordpress@example.com” — this wouldn’t do!

I searched the forums and some of the “How to” sites, but all I could find was an outdated plugin that claimed to be able to change the name.  Knowing someone else’s plugin could do it in an earlier version, I figured I could write something to do it myself, (this was a WP 3.0 installation).

One easy to deal with aspect of customizing WordPress is filter hooks – basically they’re reserved strings that hook in a function to replace, remove or add to data before it is written, (to databases, user display OR email).

Luckily, the WP Plugin API includes a filter reference, and I quickly found the needed filters.

Even sweeter… I didn’t need a plugin at all!

I wrote two short functions and added them to the site’s currently installed Theme Functions (functions.php) file.

To use them on your own WordPress installation, simply cut and paste the code into the function.php file of your theme, then edit the two strings “John Doe” and “john.doe@example.com” to whatever you’d like to use.

<?php
// ===================================================
// WordPress - change the FROM: name and email address on emails
// sent to users when they register (and other times WP sends email)
// Default name is "wordpress"
// Default address is:  "wordpress@yourdomain.com"
// ( by Randy Harris,  http://www.lexipxiel.com )
// ===================================================
//
// changes email sender's name from default "wordpress"
//
function change_from_email_name() {
$message = 'John Doe';
return $message;
}
add_filter('wp_mail_from_name', 'change_from_email_name');
//
// changes email from default "wordpress@yourdomain.com"
//
function change_from_email() {
$message = 'john.doe@example.com';
return $message;
}
add_filter('wp_mail_from', 'change_from_email');
//
//
?>

NOTES:

1). Possible Email Sending Problems: You may not be able to use just any name and email address — since WordPress is sending the email, some hosts may reject messages sent from a different server.  The safest bet, (and one users will probably appreciate), is to use a valid email address on the domain that WordPress is running on.

2). It’s Now Part of Your Theme: Once you install these functions — if you switch themes you will need to add the functions (all over again) to the new theme’s functions.php file.  The plus is that no core files have been altered, so updating WordPress (manually or automatically) is a no-brainer.

3). Advanced Users / Custom Installations: If you have already modified your installation’s core files, and want the most direct approach, you can accomplish the same results by modifying the values in your /wp-includes/pluggable.php file, (lines 371 and 395).

Resources:

WordPress Plugin API Filter Reference: http://codex.wordpress.org/Plugin_API/Filter_Reference

###

Tagged with: , , , , ,
Posted in Wordpress
3 comments on “Change WordPress FROM: (name and email address)
  1. This is the exact solution I’m looking for! However, it doesn’t work. You have curly quotes in your code, so I changed those to straight ones. Then I changed the final ?php> to ?>, and that also worked. But now I get this error:

    Warning: Cannot modify header information – headers already sent by (output started at /home/xxx/public_html/wp-content/themes/Theme1/functions.php:462) in /home/xxx/public_html/sitefiles/wp-includes/pluggable.php on line 890

    Any advice on how to fix this? Thanks!

  2. Randy Harris says:

    Hi Miriam,
    I’m pretty sure it’s a formatting error, (probably those curly quotes got munged by WP… but that’s the fodder for another How-To post)...

    I am emailing you the code directly from my functions.php file. Let’s see if that fixes it for you, (or possibly you broke some other part of your template while modifying)..

    Randy.

  3. Mike says:

    Thanks for this! I was trying to figure it out with my CMS plug-in I use for wordpress. Saved me time.

    Thanks again

    Mike

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>