Change Default wp_mail From, Without Affecting Gravity Forms

I think I found the answer on another forum discussing using Contact Form7, with the same issue I was having.

This is what I got from that thread and tried. It does appear to work and does appear to be only targeting email from the default ‘WordPress’ sender name/email.

// Change default WP email sender
add_filter('wp_mail_from', 'doEmailFilter');
add_filter('wp_mail_from_name', 'doEmailNameFilter');

function doEmailFilter($email_address){
if($email_address === "[email protected]")
    return '[email protected]';
else
    return $email_address;
}
function doEmailNameFilter($email_from){
if($email_from === "WordPress")
    return 'Site Admin';
else
    return $email_from;
}

Let me know if there is a better way to do this. Sorry if obvious…

Leave a Comment