formatting - Email sent from WordPress has HTML tags

Instead of:Hello,Thank you dfasdfasdfasdf asdf asdf asdfas dfsPlease, feelasdf asdf asdf The email that arrives in my ma

Instead of:

Hello,

Thank you dfasdfasdfasdf asdf asdf asdfas dfs

Please, feelasdf asdf asdf 

The email that arrives in my mailbox looks like the following:

<p>Hello,</p> 
<p>&nbsp;</p> 
<p>Thank you dfasdfasdfasdf asdf asdf asdfas dfs</p> 
<p>&nbsp;</p> 
<p>Please, feel asdfads fad f</p> 

So, I guess the HTML is not turned on for the wp_mail() function? How do you turn it on so the mail will arrive as it should and the <p> and <br> tags are interpreted correctly?

I am using this to send my mail from functions.php when the submit button is pressed:

   $headers = 'From: XXXXXX <[email protected]>' . "\r\n";
   $subject = 'Registration from xxxxx' . "\r\n"; 
   $message = $result_email_text;
   wp_mail($_POST['admin_email'], $subject, $message, $headers );

Instead of:

Hello,

Thank you dfasdfasdfasdf asdf asdf asdfas dfs

Please, feelasdf asdf asdf 

The email that arrives in my mailbox looks like the following:

<p>Hello,</p> 
<p>&nbsp;</p> 
<p>Thank you dfasdfasdfasdf asdf asdf asdfas dfs</p> 
<p>&nbsp;</p> 
<p>Please, feel asdfads fad f</p> 

So, I guess the HTML is not turned on for the wp_mail() function? How do you turn it on so the mail will arrive as it should and the <p> and <br> tags are interpreted correctly?

I am using this to send my mail from functions.php when the submit button is pressed:

   $headers = 'From: XXXXXX <[email protected]>' . "\r\n";
   $subject = 'Registration from xxxxx' . "\r\n"; 
   $message = $result_email_text;
   wp_mail($_POST['admin_email'], $subject, $message, $headers );
Share Improve this question edited May 16, 2019 at 23:55 butlerblog 5,1313 gold badges28 silver badges44 bronze badges asked Oct 10, 2013 at 8:26 DerfderDerfder 2,08212 gold badges34 silver badges57 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 11

The default content type is 'text/plain' which does not allow using HTML. You can set the content type of the email by including a header like "Content-type: text/html"

$headers = 'Content-type: text/html;charset=utf-8' . "\r\n";
$headers .= 'From: XXXXXX <[email protected]>' . "\r\n";
   $subject = 'Registration from xxxxx' . "\r\n"; 
   $message = $result_email_text;
   wp_mail($_POST['admin_email'], $subject, $message, $headers );

Or you can set it by using the wp_mail_content_type filter

remove_filter( 'wp_mail_content_type', 'set_html_content_type' );
add_filter( 'wp_mail_content_type', 'set_html_content_type' );
function set_html_content_type() {

    return 'text/html';
}

For more detail see the following link: http://codex.wordpress/Function_Reference/wp_mail

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

相关推荐

  • formatting - Email sent from WordPress has HTML tags

    Instead of:Hello,Thank you dfasdfasdfasdf asdf asdf asdfas dfsPlease, feelasdf asdf asdf The email that arrives in my ma

    2小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

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

关注微信