How to change the From: header field in WordPress emails

The email message header consists of a number of fields. Each field has a name and body. The body part of the From: field contains the author’s email address and name.

From: Jane Doe <janedoe@example.com>

When the wp_mail() function is used to send email, by default “wordpress@example.com” is used as the email address portion and “WordPress” is used as the name portion.

The wp_mail_from filter can be used to change the email portion.

add_filter( 'wp_mail_from', function( $from_email ) {
    $from_email = 'janedoe@example.com';
    return $from_email;
} );

The wp_mail_from_name filter can be used to change the name portion.

add_filter( 'wp_mail_from_name', function( $from_name ) {
    $from_name = 'Jane Doe';
    return $from_name;
} );

Note that all field bodies must conform to the syntax described in RFC 5322.

Posted by on .


<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>