开发者

Right way to process form text for sending email in PHP

开发者 https://www.devze.com 2023-02-08 08:28 出处:网络
I am currently processing a form with text and making an email out of the text. I am facing two problems:

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);
0

精彩评论

暂无评论...
验证码 换一张
取 消