Change Sender Name in Outgoing WordPress Email

Recommendation

Learn why I switched to WPCodeBox for managing code snippets for myself and for my clients.

Instructions

Snippet Type: PHP

  1. Copy the snippet.
  2. Add the snippet using WPCodeBox.
  3. Follow any customization notes provided.
  4. Save the snippet.
  5. Enable the snippet.
  6. Test.

Snippet

Customization Notes

  1. Adjust the ‘return ‘firstname.lastname@example.com’;’ entry as desired.
  2. Adjust the ‘return ‘FirstName LastName’;’ entry as desired.
				
					// CHANGE THE EMAIL ADDRESS
function wptu_sender_email( $original_email_address ) {
    return 'FirstName.LastName@example.com';
}
 
// CHANGE THE SENDER NAME
function wptu_sender_name( $original_email_from ) {
    return 'FirstName LastName';
}
 
// APPLY THE FILTERS
add_filter( 'wp_mail_from', 'wptu_sender_email' );
add_filter( 'wp_mail_from_name', 'wptu_sender_name' );