css - HTML email sent with wp_mail shows plain text

I have an HTML invoice that I want to send. I use the following function to replace some things in the HTMLforeach($vari

I have an HTML invoice that I want to send.

I use the following function to replace some things in the HTML

 foreach($variables as $key => $value){
  $template = str_replace('{{ '.$key.' }}', $value, $template);
}

After that I send the mail:

$to = get_option('admin_email');
$subject = "Someone reserved from ".get_bloginfo('name');
$headers = 'From: '. $email . "\r\n" .    'Reply-To: ' . $email . "\r\n";
$headers  .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html';
add_filter( 'wp_mail_content_type', 'set_html_content_type' );
function set_html_content_type() {
return 'text/html';
}

wp_mail($to, $subject, strip_tags($template), $headers);

The mail I get is like this:

Invoice article, aside, details, figcaption, figure, footer, header, hgroup, main, nav, section, summary { display: block; } audio, canvas, video { display: inline-block; } audio:not([controls]) { display: none; height: 0; } [hidden], template { display: none; } html { font-family: sans-serif; -webkit-text-size-adjust: 100%; -ms-text-size-adjust: 100%; } body { margin: 0; } a { background: transparent; } a:focus { outline: thin dotted; } a:active, a:hover { outline: 0; } h1 { margin: 0.67em 0; font-size: 2em ... 

(and the rest of the CSS), and then some HTML text without the HTML tags. So it does recognize HTML because it doesn't show <p> and other tags but it doesn't use the CSS.

I have an HTML invoice that I want to send.

I use the following function to replace some things in the HTML

 foreach($variables as $key => $value){
  $template = str_replace('{{ '.$key.' }}', $value, $template);
}

After that I send the mail:

$to = get_option('admin_email');
$subject = "Someone reserved from ".get_bloginfo('name');
$headers = 'From: '. $email . "\r\n" .    'Reply-To: ' . $email . "\r\n";
$headers  .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html';
add_filter( 'wp_mail_content_type', 'set_html_content_type' );
function set_html_content_type() {
return 'text/html';
}

wp_mail($to, $subject, strip_tags($template), $headers);

The mail I get is like this:

Invoice article, aside, details, figcaption, figure, footer, header, hgroup, main, nav, section, summary { display: block; } audio, canvas, video { display: inline-block; } audio:not([controls]) { display: none; height: 0; } [hidden], template { display: none; } html { font-family: sans-serif; -webkit-text-size-adjust: 100%; -ms-text-size-adjust: 100%; } body { margin: 0; } a { background: transparent; } a:focus { outline: thin dotted; } a:active, a:hover { outline: 0; } h1 { margin: 0.67em 0; font-size: 2em ... 

(and the rest of the CSS), and then some HTML text without the HTML tags. So it does recognize HTML because it doesn't show <p> and other tags but it doesn't use the CSS.

Share Improve this question edited May 17, 2019 at 0:03 butlerblog 5,1313 gold badges28 silver badges44 bronze badges asked May 13, 2014 at 17:17 MichaelAngeloMichaelAngelo 1011 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 2

You are passing the content of the message through the strip_tags() function. The result is the content of the email with the HTML tags striped. Try not using that function.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745485994a4629770.html

相关推荐

  • css - HTML email sent with wp_mail shows plain text

    I have an HTML invoice that I want to send. I use the following function to replace some things in the HTMLforeach($vari

    1小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信