Override the from email address and from name in WordPress

This is useful when dealing with contact forms within WordPress. Just add these lines to your theme’s functions.php file and replace the variables $from_email and $from_name with your credentials.

// OVERRIDE THE FROM EMAIL ADDRESS
add_filter('wp_mail_from', 'new_mail_from');
add_filter('wp_mail_from_name', 'new_mail_from_name');

$from_email = "myemail@domain.com";
$from_name = "myname";

function new_mail_from($old) {
	return $from_email;
}
function new_mail_from_name($old) {
	return $from_name; 
}

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s