WordPress Plugins

How to Change the Email Sender in WordPress

August 22, 2014

On a daily basis as WordPress site owners, we receive email notifications when someone submitted a comment when a user signed up or did something that required that WordPress send us an Email.

This email by default used a generic name and address in the form sender.

1From name: WordPress
2From address: wordpress@your-domain.com
Email Generic Address

Sometimes a client or ourselves want to customize this address, basically to avoid the filtered spam or just for aesthetic, to archive this there are two ways to do that.

Programmatically Change Email Sender in WordPress

WordPress as always offers a couple of filters to hook and change those values.

In your functions.php file, you need to add the custom filters, the first one will be wp_mail_from_name to change the “WordPress” string.

1<?php 
2
3function ec_mail_name( $email ){
4  return 'Joe Doe'; // new email name from sender.
5}
6add_filter( 'wp_mail_from_name', 'ec_mail_name' );

As you can see, the filter function just needs to return the name that you want to use.

The second filter is wp_mail_from and with this filter, we’ll change the from address.

1<?php 
2 
3function ec_mail_from ($email ){
4  return 'joe@doe.com'; // new email address from sender.
5}
6add_filter( 'wp_mail_from', 'ec_mail_from' );

Same as the wp_mail_from_name, the filter function just needs to return the email address to use as the from address.

Use a Plugin to Change Email Sender in WordPress

Lately, I have been using the first option to change the sender address, copying and pasting the same code over and over, so I decided to create a simple plugin to take care of this task.

WP Simple Mail Sender Plugin.

WP Simple Mail Sender is a very simple plugin to change the sender address and name in WordPress outgoing emails.

WP Simple Mail Sender allows you to use the values in the General setting, Site Title and the Admin Email instead of the default value WordPress wordpress@yourdomain.com also you can use custom values as well, you can configure the From Address and From Name if you do not want to use the General settings values.

Get the zip file.

Right now the plugin is awaiting review to be hosted in the WordPress.org official repositories, But meanwhile you can download it from my Github Account or directly wp-simple-email-sender.zip

You can download the zip file directly from the official WordPress repo http://wordpress.org/plugins/wp-simple-mail-sender/ or install the plugin as any other WordPress Plugin.

Enrique

Written by Tmeister

Enrique Chavez is a full-stack developer with almost 20 years of experience in the industry. he is an extremely versatile developer working on a plethora of projects, from startups to established companies.

Are you ready to take the plunge? Drop me a line, and let’s chat about your idea!