I am currently processing a form with text and making an email out of the text.
I am facing two problems: 1) If I just take the text as is, I get \n\r that appear in the email whenever the person uses line breaks.
2) If I use nl2br() function开发者_运维知识库 on the input text, I get
strings in my email.Is there a correct or "best practice" way handling such situations?
Thanks, Alex
You should add appropriate headers to your email
// To send HTML mail
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
before using nl2br()
// Then mail it
mail($to, $subject, nl2br($message), $headers);
精彩评论