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. Link to comment https://forums.phpfreaks.com/topic/235944-line-breaks-rn-are-showing-up-in-html-email/ 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']); Link to comment https://forums.phpfreaks.com/topic/235944-line-breaks-rn-are-showing-up-in-html-email/#findComment-1212901 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 Link to comment https://forums.phpfreaks.com/topic/235944-line-breaks-rn-are-showing-up-in-html-email/#findComment-1212904 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"]); Link to comment https://forums.phpfreaks.com/topic/235944-line-breaks-rn-are-showing-up-in-html-email/#findComment-1212908 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); Link to comment https://forums.phpfreaks.com/topic/235944-line-breaks-rn-are-showing-up-in-html-email/#findComment-1477992 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.