WordPress set mail type to html

black and gray digital device
Photo by Torsten Dettlaff on Pexels.com

//Create function which will return content type

function set_html_content_type() {
     return 'text/html';
 }

//now add filter before wp-mail()

add_filter( 'wp_mail_content_type', 'set_html_content_type' ); // add content filter to html
 wp_mail($to, $subject, $message,$headers);
 remove_filter( 'wp_mail_content_type', 'set_html_content_type' ); // remove content filter

//remove filter after wp_mail()

 

By milind

Milind is a Senior WordPress Engineer at rtCamp. WordPress Ecosystem Contributor and AMP Support Engineer.

Leave a comment

Your email address will not be published. Required fields are marked *