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