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 Referencehttp://codex.wordpress.org/Plugin_API/Filter_Reference

###