Send HTML Emails Using wp_mail Function

WordPress’s wp_mail() function default content type is text/plain which does not allow using HTML. To send HTML emails you need to set the content type of the email to text/html by using the wp_mail_content_type filter. This is how you can do that

WordPress’s wp_mail() function default content type is ‘text/plain’ which does not allow using HTML. To send HTML emails you need to set the content type of the email to “text/html” by using the ‘wp_mail_content_type’ filter. This is how you can do that:

before you call your wp_mail add a filter to wp_mail_content_type to return ‘text/html’ as the content type.

add_filter('wp_mail_content_type', create_function('', 'return "text/html"; '));
wp_mail('whoever@whatever.com', 'Subject', 'Message');

Don’t forget to set the content type filter to “text/plain” after you use the wp_mail function, to avoid any conflicts.

Full code will be

add_filter('wp_mail_content_type', create_function('', 'return "text/html"; '));
wp_mail('whoever@whatever.com', 'Subject', 'Message');
remove_filter( 'wp_mail_content_type',create_function('', 'return "text/plain"; ') );

List Mag WP Menu
Join our feeds to automatically receive the latest headlines, news, and information formatted for your club's website or news reader.