使用wp_mail()发送HTML电子邮件时CSS不起作用

时间:2022-06-25 15:05:36

I am trying to send a HTML mail with the Wordpress function wp_mail() like this:

我正在尝试使用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' );

All HTML tags like <strong>, <li>, <p> etc. come with HTML format. But when I try to change the color using HTML or CSS like <li style="color:red">Word</li> or <li color="red">Word</li> it won't work and appears as blank text.

所有HTML标记(如,

  • ,

    等)都以HTML格式提供。但是,当我尝试使用HTML或CSS(如

  • Word 或
  • Word )更改颜色时,它将无效并显示为空白文本。

  • What am I doing wrong?

    我究竟做错了什么?

    2 个解决方案

    #1


    The text/message you send is in $_POST['mail_text'] coming from a textarea, right? Did you echo out the content of $_POST['mail_text']? Is it ok before sending?

    您发送的文本/消息来自textarea的$ _POST ['mail_text'],对吧?你是否回应了$ _POST ['mail_text']的内容?发送前没问题吗?

    Try single quotes:

    试试单引号:

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

    and check if somewhere a script calls strip_tags to remove html tags.

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

    #2


    $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.">";
    

    user this headers in email for sending html

    用户在电子邮件中使用此标题发送html

    #1


    The text/message you send is in $_POST['mail_text'] coming from a textarea, right? Did you echo out the content of $_POST['mail_text']? Is it ok before sending?

    您发送的文本/消息来自textarea的$ _POST ['mail_text'],对吧?你是否回应了$ _POST ['mail_text']的内容?发送前没问题吗?

    Try single quotes:

    试试单引号:

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

    and check if somewhere a script calls strip_tags to remove html tags.

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

    #2


    $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.">";
    

    user this headers in email for sending html

    用户在电子邮件中使用此标题发送html