Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Instead of:

Hello,

Thank you dfasdfasdfasdf asdf asdf asdfas dfs

Please, feelasdf asdf asdf 

I am getting something like this in the email that arrives to my mailbox:

<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 to 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.com <info@xxxxx.com>' . "\r\n";
   $subject = 'Registration from xxxxx.com' . "\r\n"; 
   $message = $result_email_text;
   wp_mail($_POST['admin_email'], $subject, $message, $headers );
share|improve this question
add comment

1 Answer

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.com <info@xxxxx.com>' . "\r\n";
   $subject = 'Registration from xxxxx.com' . "\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 below link http://codex.wordpress.org/Function_Reference/wp_mail

share|improve this answer
    
THanks, it's working nice if you are using English. Please, change the charset in your answer to something that is more universal, because unless it's English you would heve problems using iso-8859-1 and it's not recommended anymore to use iso-8859-1. Thanks. –  Derfder Oct 10 '13 at 13:26
    
@Derfder thanks –  Dipali Dhole Oct 10 '13 at 13:36
    
@Derfder Please accept the answer.so this answer will notify as right and it's useful for the other users. –  Dipali Dhole Oct 10 '13 at 13:47
    
Please, add to your answer something like charset=utf-8 so it is universal, thanks. –  Derfder Oct 10 '13 at 15:27
    
@Derfder Thanks –  Dipali Dhole Oct 10 '13 at 18:21
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.