3 mail headers which you could modify in wp_mail() function

We would like to show you three different wp_mail filters, which you could use to modify outgoing emails headers.

  • wp_mail_content_type – modifies mail content type e.g. if you want to use html tags in your email you should set ‘text/html’ type instead of default ‘text/plain’.
  • wp_mail_from – modifies from email address
  • wp_mail_from_name – modifies from email address

Modifying wp_mail() headers

/* mail content type */
add_filter( 'wp_mail_content_type','my_mail_content_type' );
function my_mail_content_type(){
	return "text/html";
}

/* from address */
add_filter( 'wp_mail_from', 'my_mail_from' );
function my_mail_from( $email )
{
	return 'info@'.$_SERVER['SERVER_NAME'];
}

/* from name*/
add_filter( 'wp_mail_from_name', 'my_mail_from_name' );
function my_mail_from_name( $name )
{
	return 'Your mail from name';
}

For mail from address domain (wp_mail_from filter), we decided to use server environment information instead of hardcoding domain name.

You can also modify this headers in $headers parameter of each wp_mail() function call. However we think that adding functions mentioned above to functions.php is more universal solution rather than defining headers each time you call wp_mail() function.

More filters

We also would like to mention wp_mail_charset filter. Which could be use in cases then you need change mail characters encoding.