Noah Goodrich
Noah Goodrich

Reputation: 227

Can't get nl2br to work using PHP mailer

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 it 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?

Upvotes: 0

Views: 953

Answers (3)

Ramje
Ramje

Reputation: 186

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().

Upvotes: 1

Olli
Olli

Reputation: 752

Please try this:

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

Upvotes: 0

DRiFTy
DRiFTy

Reputation: 11369

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

Upvotes: 0

Related Questions