【问题标题】:CSS won't work when sending HTML email with wp_mail()使用 wp_mail() 发送 HTML 电子邮件时,CSS 将不起作用
【发布时间】:2015-07-20 00:19:57
【问题描述】:

我正在尝试使用 Wordpress 函数 wp_mail() 发送 HTML 邮件,如下所示:

add_filter( 'wp_mail_content_type', function( $content_type ) { return 'text/html'; });
$headers = 'From: '. $current_user->user_firstname . ' ' . $current_user->user_lastname .' <'. $current_user->user_email .'>' . "\r\n";
wp_mail( $_POST['email'], $_POST['subject'], $_POST['mail_text'], $headers);
remove_filter( 'wp_mail_content_type', 'set_html_content_type' );

&lt;strong&gt;&lt;li&gt;&lt;p&gt; 等所有 HTML 标签都带有 HTML 格式。但是,当我尝试使用 HTML 或 CSS(如 &lt;li style="color:red"&gt;Word&lt;/li&gt;&lt;li color="red"&gt;Word&lt;/li&gt;)更改颜色时,它不起作用并显示为空白文本。

我做错了什么?

【问题讨论】:

    标签: php html css wordpress email


    【解决方案1】:
    $headers  = "MIME-Version: 1.0" . "\n";
        $headers .= "Content-type: text/html; charset=iso-8859-1" . "\n";
        $headers .= "X-Priority: 1 (Higuest)\n";
        $headers .= "X-MSMail-Priority: High\n";
        $headers .= "Importance: High\n";
    
        $headers .= "From: Approprice <".$mailfrom.">" . "\n";
        $headers .= "Return-Path: Approprice <".$mailfrom.">" . "\n";
        $headers .= "Reply-To: Approprice <".$mailfrom.">";
    

    在电子邮件中使用此标头以发送 html

    【讨论】:

      【解决方案2】:

      您发送的文本/消息是来自文本区域的$_POST['mail_text'],对吗? $_POST['mail_text']的内容你有呼应吗?发送前可以吗?

      试试单引号:

      <li style='color:#f90'>Hello World</li>
      

      并检查某处是否有脚本调用strip_tags 来删除html标签。

      【讨论】:

        猜你喜欢
        • 2016-09-20
        • 2012-12-14
        • 2012-09-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-09-23
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多