worldnews — 2011-01-09T01:25:40-05:00 — #1
When I send an email in Php which email was generated based on a form textarea the email is full of \r\
wherever a new line was entered by the sender of the message!
How does one remove these r/n in a Php generated email, I mean via this:
mail($email, $subject, $message, $headers);
and have normal break/new lines instead in the body of the email?
paul_wilkins — 2011-01-09T02:56:03-05:00 — #2
It seems that the content of the email is being escaped incorrectly. The solution is not to remove them after the fact, but to work back to where the problem begins, and correctly deal with it there and then.
If $message contains "Line one.\r\
Line two." you won't see the \r\
. It's only when $message is escaped, either incorrectly or multiply, that you see the problem.
What does var_dump($message) show, and how far up through the code do you need to go before a change in $message occurs?
worldnews — 2011-01-09T13:25:37-05:00 — #3
I figured out the problem.
The message which is a POST from a form TEXTAREA was being done this: mysql_real_escape_string
for insertion into the MySQL table. This action was introducing the r/ns for each new line. So now I am creating 2 version of the body of the message, one that is included in the email without the mysql_real_escape_string and one that is inserted into the MySQL table with the mysql_real_escape_string.
paul_wilkins — 2011-01-09T14:42:08-05:00 — #4
That's where it helps to escape at the very last moment, as is demonstrated in the mysql_query examples.
The message really should be properly escaped for each of its intended outputs. When outputting the message to the email, is there a proper way to correctly escape the message? It seems that there should be.
worldnews — 2011-01-10T00:10:57-05:00 — #5
Well I tell you I ma having the darnest of time with this outputting of the message properly.
That is the message is displaying Ok in email, that is with exact number of line spacing, but in the Web page the line spacing is reduced by 1/2 half.
So 1 line spacing is shown with NO line spacing and 2 as 1.
And as noted now I am nl2br() the message when shown on the web page but sending the not nl2br() ed version via the email.
To be exact this is not a critical problem, but very annoying putting it mildly. I mean if you have 1 line spacing between 2 paragraph, you want that to show.
So for example if message is entered by user like this:
after I retrieve this message from MySQL to display on the web page, then it displays it like