The wp_mail_from
filter modifies the "from email address" used in an email sent using the wp_mail function. When used together with the 'wp_mail_from_name' filter, it creates a from address like "Name <email@address.com>". The filter should return an email address.
add_filter( 'wp_mail_from', 'custom_wp_mail_from' );
function custom_wp_mail_from( $original_email_address ) {
//Make sure the email is from the same domain
//as your website to avoid being marked as spam.
return 'webmaster@mydomainname.com';
}
It is not necessary to call another method if you can use anonymous functions (PHP 5.3.0+):
add_filter( 'wp_mail_from', function( $email ) {
return 'webmaster@mydomainname.com';
});
remove_filter()
.Since: Version 2.2
wp_mail_from
is located in wp-includes/pluggable.php