santobugito Posted July 23, 2009 Share Posted July 23, 2009 I have an issue with incorrectly formatted emails On a form I enter the text 1 2 3 4 When saved to database it is saved a above, but when the email (html formatted via server 2003 smtp server) is sent, it comes out as 1\r\n2\r\n3\r\n4 I've tried doing a replace with <br> and <p> and also /n, but with no luck. Any ideas on this would save my hair! Link to comment https://forums.phpfreaks.com/topic/167130-solved-sent-emails-displaying-rn-instead-of-line-feed/ Share on other sites More sharing options...
ignace Posted July 23, 2009 Share Posted July 23, 2009 Notice the double-quotes. $contents = str_replace("\r\n", '', $contents); Link to comment https://forums.phpfreaks.com/topic/167130-solved-sent-emails-displaying-rn-instead-of-line-feed/#findComment-881227 Share on other sites More sharing options...
Andy17 Posted July 23, 2009 Share Posted July 23, 2009 I have had the exact same problem a few times. What fixed it for me was to send the e-mail and then use mysql_real_escape_string() after the message has been sent rather than before. The escaping caused the same problem for me as the one you stated. Link to comment https://forums.phpfreaks.com/topic/167130-solved-sent-emails-displaying-rn-instead-of-line-feed/#findComment-881305 Share on other sites More sharing options...
santobugito Posted July 24, 2009 Author Share Posted July 24, 2009 I have had the exact same problem a few times. What fixed it for me was to send the e-mail and then use mysql_real_escape_string() after the message has been sent rather than before. The escaping caused the same problem for me as the one you stated. No luck on this one I now get Message : \'b\\r\\nv\\r\\nc\\r\\nx\' Also doing the replace in reply 1 didn't help either. The code for generating the text is function email_alert_assigned_only($tid, $msgid=false, $msg=false, $subject=false) { //alerts the alert_user (in mail) global $config, $db_table; $tid=preg_replace('/\D+/', '', $tid); //sanitise $msgid=preg_replace('/\D+/', '', $msgid); //sanitise if (empty($tid)) { return; } $t = mysql_fetch_array(mysql_query("SELECT * FROM ".$db_table['tickets']." WHERE ID=".$tid)); $cat = get_category($t['cat']); if (!empty($msgid)) { $m = mysql_fetch_array(mysql_query("SELECT * FROM ".$db_table['messages']." WHERE ID=".$msgid)); } $from = $config['alert_email']; $alert_subj = str_replace("Message","Private Message",$config['alert_subj']); //$alert_msg = "You have a new private message for ticket ".$tid." $alert_msg = "There is a new private message for ticket %ticket From: %name (%email) Message : %message http://site/admin.php?a=view&id=%ticket %url "; $vars=array(); $vars['ticket']=$t['ID']; $vars['subject']=$subject? $subject: htmlspecialchars_decode($t['subject']); $vars['category']=$cat['name']; $vars['cat_name']=$cat['name']; $vars['name']=$t['name']; $vars['email']=$t['email']; $vars['datetime']=(empty($m))?'': format_time('r', time_convert($m['timestamp'])); //$msg = str_replace("'", "\"", $msg); $vars['message']=$msg ? htmlspecialchars_decode($msg) : htmlspecialchars_decode($m['message']); $alert_subj=Keywords($alert_subj,$vars); $text=Keywords($alert_msg,$vars); if ($html=GetHTML($alert_msg,$vars,'email.html')) { $body=array(); $body['text']=$text; $body['html']=$html; } else { $body['html']=text2html($text); } $pri=$t['priority'] == 3?1:''; //replace bit below with get recipient $to = ''; $rep=$t['rep']; if ($rep != "") { $rows = mysql_fetch_array(mysql_query("SELECT * FROM ".$db_table['reps']." WHERE ID=".$rep)); $to = $rows['email']; } if (!empty($to)) { send_mail($to, $alert_subj, $body, $from, false, $pri); } } Link to comment https://forums.phpfreaks.com/topic/167130-solved-sent-emails-displaying-rn-instead-of-line-feed/#findComment-881781 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.