You are currently viewing Set the Content Type Email from Text/Plain to Text/HTML in WordPress

Set the Content Type Email from Text/Plain to Text/HTML in WordPress

WordPress use wp_mail() function to send emails. You can also find how to send custom email using wp_mail() function to send email using wordpress. Here you will know how to send HTML email instead of plain text.

Add the following code to the functions.php file of your WordPress theme or in your custom plugin.

//Set mail content as html
function set_mail_html_content_type(){
    return "text/html";
}
add_filter( 'wp_mail_content_type','set_mail_html_content_type' );
//Set mail content as plain text
function set_plain_html_content_type(){
    return "text/plain";
}
add_filter( 'wp_plain_content_type','set_plain_html_content_type' );

Below code show how to use html email format.

function send_custom_email($to, $subject, $message, $headers) {
	add_filter( 'wp_mail_content_type', 'set_mail_html_content_type' );
	wp_mail( $to, $subject, $message, $headers); 
	remove_filter( 'wp_mail_content_type', 'set_mail_html_content_type' );
}

Leave a Reply