Thumper Posted May 18, 2008 Share Posted May 18, 2008 My web site has a Contact page but the emails I receive from it are one long string interspersed with \r\n instead of newLine characters where appropriate. How do I resolve this? Link to comment https://forums.phpfreaks.com/topic/106217-removing-rn-from-form-generated-email/ Share on other sites More sharing options...
LooieENG Posted May 18, 2008 Share Posted May 18, 2008 Try the nl2br() function Link to comment https://forums.phpfreaks.com/topic/106217-removing-rn-from-form-generated-email/#findComment-544434 Share on other sites More sharing options...
resago Posted May 18, 2008 Share Posted May 18, 2008 try "" instead of ' ' Link to comment https://forums.phpfreaks.com/topic/106217-removing-rn-from-form-generated-email/#findComment-544461 Share on other sites More sharing options...
Thumper Posted May 18, 2008 Author Share Posted May 18, 2008 Tried the nl2br() function but still getting the same result. e.g. if i enter... Hi, Love the site, Dave. ...and hit enter, I get "Hi,\r\nLove the site,\r\nDave." in my email. The code is quite simple : if (isset($_POST['submit'])) // Handle the form. { // Check for an email address. if (eregi ("^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,4}$", stripslashes(trim($_POST['email'])))) { $e = escape_data($_POST['email']); } else { $e = FALSE; echo '<p><font color="red" size="+1">Please enter a valid email address!</font></p>'; } // Check for a subject line. if (!(trim($_POST['subject'])=="")) { $s = escape_data($_POST['subject']); } else { $s = FALSE; echo '<p><font color="red" size="+1">Please enter a valid subject line!</font></p>'; } // Check for text in the comments box. if (!(trim($_POST['comments'])=="")) { $c = escape_data($_POST['comments']); } else { $c = FALSE; echo '<p><font color="red" size="+1">Please enter your comments!</font></p>'; } ############################################# if ($e && $s && $c) # everything is okay... ############################################# { $MailTo=$adminEmail; if (mail($MailTo, $s, nl2br($c), "From: $e")) } } Link to comment https://forums.phpfreaks.com/topic/106217-removing-rn-from-form-generated-email/#findComment-544468 Share on other sites More sharing options...
resago Posted May 18, 2008 Share Posted May 18, 2008 what do you get if you don't escape the comment? Link to comment https://forums.phpfreaks.com/topic/106217-removing-rn-from-form-generated-email/#findComment-544477 Share on other sites More sharing options...
DarkWater Posted May 18, 2008 Share Posted May 18, 2008 They should appear as newlines in the e-mail client. Link to comment https://forums.phpfreaks.com/topic/106217-removing-rn-from-form-generated-email/#findComment-544502 Share on other sites More sharing options...
Thumper Posted May 20, 2008 Author Share Posted May 20, 2008 I removed the "escape_data" function and now i get <br /> on the end of each line, e.g.: Hi,<br /> Love the site,<br /> Dave.<br /> Any more suggestion, guys? Please. Link to comment https://forums.phpfreaks.com/topic/106217-removing-rn-from-form-generated-email/#findComment-545944 Share on other sites More sharing options...
MatthewJ Posted May 20, 2008 Share Posted May 20, 2008 How about $array = array("\r\n", "\n\r", "\n", "\r"); $var = str_replace($array, "<br />", $var); Link to comment https://forums.phpfreaks.com/topic/106217-removing-rn-from-form-generated-email/#findComment-545948 Share on other sites More sharing options...
Thumper Posted May 20, 2008 Author Share Posted May 20, 2008 That should have read... removed the "escape_data" function and now i get <br /> on the end of each line, e.g.: Hi,<br /> Love the site,<br /> Dave.br /> Any more suggestion, guys? Please. Link to comment https://forums.phpfreaks.com/topic/106217-removing-rn-from-form-generated-email/#findComment-545950 Share on other sites More sharing options...
marcus Posted May 20, 2008 Share Posted May 20, 2008 You need to make the message read HTML using the mail headers. Link to comment https://forums.phpfreaks.com/topic/106217-removing-rn-from-form-generated-email/#findComment-545954 Share on other sites More sharing options...
Thumper Posted May 20, 2008 Author Share Posted May 20, 2008 Thanks to one and all - I've now got this working as required. See you all again soon, Dave. Link to comment https://forums.phpfreaks.com/topic/106217-removing-rn-from-form-generated-email/#findComment-545981 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.