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;
精彩评论