首页 > 解决方案 > wp_mail sending only plain text messages

问题描述

I am sending some emails using wp_mail() function to send some HTML formatted emails. The problem is that the emails all look like basic plain text.

I set my headers to

$headers = array('Content-Type: text/html; charset=UTF-8');

In Windows, I use Fake SMTP server to test. The Content/Type is being recognized as text/html; charset=UTF-8

The problem is that all my emails look like basic plain text. No spacing from divs, no tables, no CSS modifications, nothing. It basically takes the text from the HTML that I wrote and puts it inline. I also tried sending the emails to GMAIL and no luck, it looks the same.

I ran out of options with testing this. What should I change?

标签: htmlwordpressemail

解决方案


您是否在 functions.php 中启用了 HTML 标头

add_filter( 'wp_mail', function( $params ) {
  $params['headers'] = 'Content-type: text/html';
  return $params;
} );

推荐阅读