rdp
rdp

Reputation: 2088

retaining line breaks in email body

I have a feedback form where the user can enter his/her feedbacks in a textarea. When the form is submitted I am using the php mail function to get all the user details into my mail.

mail( "[email protected]", "Subject: Comments posted by $postedBy", $message, "From: $emailID" );

Here $message is the user comments. But I get something like this in the email body.

Hi.test line break\r\nnew line\r\nnewline 2\r\ntest again\r\nagain.

The line breaks in text area are showing up in the mail. How can I fix this?

Edit:

$message = mysql_real_escape_string($_POST['comments']);

Upvotes: 1

Views: 2232

Answers (3)

lszrh
lszrh

Reputation: 1582

Are the \r\n directly displayed or is all in one line without seeing \r\n? For last I think you have to set the correct content-type. In example 4 on http://php.net/manual/en/function.mail.php you can see how to set the content-type. But you have to use plain/text for that.

EDIT: After your edit: mysql_real_escape maskes all linebreaks. use $_POST['comment'] on your mail()-call to have it working!

mail($to, $subject, $_POST['comment'], $from);

Upvotes: 2

hangar18
hangar18

Reputation: 638

I'm not sure if you've tried this but can you try replacing the "\r\n" with "<br>".
Alternatively see if you can change the email mime type
Check this
http://php.bigresource.com/Email-MIME-Types-KesYPexl.html

Upvotes: -1

Your Common Sense
Your Common Sense

Reputation: 157828

There is some function in your code that replaces newline characters with \r\n.
just trace your code and see, where this replacement takes place, and remove it.
Not a big deal

Upvotes: 2

Related Questions