Okay, I’ve got the following issue. I’m trying to send a mail in HTML format. I made a class that returns an HTML string, and that works great.
When I pass that html-mail as $message in my function, works also. But it will not send as html, but plain text.
Now I’ve tried the following things:
1)
$headers = array('Content-Type: text/html; charset=UTF-8');
wp_mail($to, $subject, $message, $headers);
2)
$headers="MIME-Version: 1.0" . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
3)
$headers="MIME-Version: 1.0" . "\r\n";
$headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n";
4)
function wpse27856_set_content_type(){
return "text/html";
}
add_filter( 'wp_mail_content_type','wpse27856_set_content_type' );
What else could it be?
2 Answers
Try this one.
add_filter( 'wp_mail_content_type', 'wpdocs_set_html_mail_content_type' );
$to = 'sendto@example.com';
$subject="The subject";
$body = 'The email body content';
$headers = array('Content-Type: text/html; charset=UTF-8');
wp_mail( $to, $subject, $body , $headers);
// Reset content-type to avoid conflicts -- https://core.trac.wordpress.org/ticket/23578
remove_filter( 'wp_mail_content_type', 'wpdocs_set_html_mail_content_type' );
function wpdocs_set_html_mail_content_type() {
return 'text/html';
}