开发者

Can't get nl2br to work using PHP mailer

开发者 https://www.devze.com 2023-04-05 07:29 出处:网络
I\'m trying to post some information from the previous page, and then email it out. The info that is posted from the previous page is inside a text area, and I want i开发者_如何学Pythont to automati

I'm trying to post some information from the previous page, and then email it out.

The info that is posted from the previous page is inside a text area, and I want i开发者_如何学Pythont to automatically add new lines when the user has pressed enter when typing in that text area.

Tried using nl2br, it doesn't seem to work. My code:

Posting from previous page:

$BREAKINGNEWS=nl2br($_POST['BREAKINGNEWS']);

Taking that info and putting it into the email's message:

$message .=  nl2br($BREAKINGNEWS);

As you can see I have put it twice, but it still doesn't work and prints out \r\n at the end of each line.

I've tried doing it just on the POST and just on the $message but it refuses to work.

Any ideas?


You might be using SQL escaping, You should only apply SQL escaping when the output is going to be used in a SQL query. Try to not escape the data when you use nl2br().


Replace "\r\n" with "\n"?

$text = nl2br(str_replace("\r\n", "\n", $_POST['BREAKINGNEWS']));

EDIT: Are you setting IsHTML(true) in PHPMailer?

$mail = new PHPMailer();
$mail->IsHTML(true);


Please try this:

$text = str_replace("\r\n", "
", $text;
0

精彩评论

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

关注公众号