-1

By default, wp_mail function does not support displaying formatted emails. For example, notifications of new comments that have formatted text shows HTML-tags displaying like a plain text.

I solved this problem by adding the following code to the functions.php file:

function set_html_mail_content_type(){
    return "text/html";
}
add_filter( 'wp_mail_content_type','set_html_mail_content_type' );

After that, emails began to come with formatted text and without HTML tags.

But another problem appears. The whole email comes in continuous text: no new lines and no paragraphs: It’s just that all sentences are in a one row.

Do you have any idea what it might be related to?

Yuri
  • 55
  • 10
  • _“Do you have any idea what it might be related to?”_ - it is of course related to the very basic fact, how HTML treats whitespace … – CBroe Sep 18 '20 at 11:40

1 Answers1

0

I usually handle this by passing the content type in the headers parameter for wp_mail()

For example...

$to = 'john.doe@example.com';
$subject = 'HTML Test';
$body = '<html>...</html>';
$headers = [
  'Content-Type' => 'text/html; charset=UTF-8'
];

wp_mail( $to, $subject, $body, $headers );

More info here: https://developer.wordpress.org/reference/functions/wp_mail/

Hope this answers your question.

Levi Cole
  • 3,561
  • 1
  • 21
  • 36
  • Thank you Levi Cole! Where should I add these lines to prevent removing them after WP update? – Yuri Sep 21 '20 at 10:20