sh0wtym3 Posted May 9, 2011 Share Posted May 9, 2011 I have a simple contact form with a textarea field, where the visitor can type a message in. However, if the user enters paragraphs or any type of line breaks, then the email that is sent shows the "\r\n" characters. I've tried using the nl2br function to no avail. Here's a sample code snippet: $message = $_POST["message"]; // To send HTML mail, the Content-type header must be set $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; // Additional headers $headers .= 'From: '. $_POST["email"]; mail($to, $subject, $message, $headers); Am I missing something? Besides the "\r\n" characters showing, everything else works fine. Quote Link to comment Share on other sites More sharing options...
AbraCadaver Posted May 9, 2011 Share Posted May 9, 2011 Either turn off magic_quotes_gpc in php.ini, or: stripslashes($_POST['message']); Quote Link to comment Share on other sites More sharing options...
sh0wtym3 Posted May 9, 2011 Author Share Posted May 9, 2011 I applied that function as follows: $message = stripslashes($_POST["message"]); However instead of "\r\n" characters showing up everywhere, "rn" characters show up everywhere Quote Link to comment Share on other sites More sharing options...
sh0wtym3 Posted May 9, 2011 Author Share Posted May 9, 2011 Here's a solution, for others who may wander into this thread: $message = str_replace('\r\n', '<br />', $_SESSION["message"]); Quote Link to comment Share on other sites More sharing options...
pauliak1 Posted May 3, 2014 Share Posted May 3, 2014 this worked for me: $message = str_replace('\r\n\r\n', '\r\n', $message); $message = str_replace('\r\n', "\n\r", $message); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.