WordPress Sender Email Address

When your WordPress website send emails, if the sender email address isn’t specified in code it’ll default to sending as wordpress@example.org. You probably don’t want your clients to see this. Instead, you’ll probably want to go with something like hello@example.com or no-reply@example.org.

noteTo apply this simple modification, you’ll need to be using a custom child theme so you can modify your functions.php file.

Create a new file called functions-rewrite-sender.php in your custom child theme’s folder and paste the following into it.

<?php

/**
 * Rewrite the sender name and/or address in outgoing emails.
 */

// Block direct access.
if (!defined('WPINC')) {
	exit('Do NOT access this file directly.');
}

/**
 * Rewrite the outgoing email sender's name.
 */
function hw_rewrite_mail_sender_name($email_name) {
	if (defined('HW_MAIL_SENDER_NAME') && !empty(HW_MAIL_SENDER_NAME)) {
		$email_name = (string) HW_MAIL_SENDER_NAME;
	}

	return $email_name;
}
add_filter('wp_mail_from_name', 'hw_rewrite_mail_sender_name');

/**
 * Rewrite the outgoing email sender's address.
 */
function hw_rewrite_mail_sender_address($email_address) {
	if (defined('HW_MAIL_SENDER_ADDRESS') && !empty(HW_MAIL_SENDER_ADDRESS)) {
		$email_address = (string) HW_MAIL_SENDER_ADDRESS;
	}

	return $email_address;
}
add_filter('wp_mail_from', 'hw_rewrite_mail_sender_address');

All we do here is hook two standard WordPress filters wp_mail_from & wp_mail_from_name, and override the returned strings if we’ve set the relevant constant.

To use this snippet, just add the following to functions.php in your custom child theme.

// Rewrite the sender/from for outgoing emails.
// define('HW_MAIL_SENDER_NAME', 'My Super Website');
// define('HW_MAIL_SENDER_ADDRESS', 'hello@example.org');
require_once 'functions-rewrite-sender.php';

Uncomment the two define() lines and set the name and sender email address you want to apply to your outgoing emailts. It’s a nice little tweak, a clean way of harmonising outgoing emails from your website.

Testing the Sender Email

Install something like the WP Test Email plugin then send an email to an address that your website doesn’t know about. If your website is www.example.org, don’t send your test email to hello@example.org. Send the test email to a personal GMail/Outlook/Whatever address so you can get a clear idea of what your customers will actually see.

When you receive the test email and you’re happy with the sender name/email, also try to check the headers of your outgoing emails…

Happy emailing!

2 thoughts on “WordPress Sender Email Address”

Leave a Comment

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