Dismal_Bliss Posted May 30, 2010 Share Posted May 30, 2010 In my script I am hacking, the body of an email imported into a discussion board must then be sent out to all subscribed users. The problem I am having is that the \n emails being sent \n\n have these new line markers \n\n in them \n I need to know what to do so that in the emails, the \n is replaced by an actual new line or carriage return. Thanks! - Bob Quote Link to comment https://forums.phpfreaks.com/topic/203326-converting-n-into-real-line-breaks-in-email-messages/ Share on other sites More sharing options...
kenrbnsn Posted May 30, 2010 Share Posted May 30, 2010 Code please. Quote Link to comment https://forums.phpfreaks.com/topic/203326-converting-n-into-real-line-breaks-in-email-messages/#findComment-1065239 Share on other sites More sharing options...
ZachMEdwards Posted May 30, 2010 Share Posted May 30, 2010 Make sure you aren't doing $newline = '\n'; You need to do $newline = "\n"; #or $newline = "\r\n"; But please post some code Quote Link to comment https://forums.phpfreaks.com/topic/203326-converting-n-into-real-line-breaks-in-email-messages/#findComment-1065241 Share on other sites More sharing options...
kenrbnsn Posted May 30, 2010 Share Posted May 30, 2010 If you are sending HTML formatted email messages, the "\n" characters must be converted to "<br>" tags by using the nl2br function. Ken Quote Link to comment https://forums.phpfreaks.com/topic/203326-converting-n-into-real-line-breaks-in-email-messages/#findComment-1065243 Share on other sites More sharing options...
Dismal_Bliss Posted May 31, 2010 Author Share Posted May 31, 2010 Code please. Here is the code of the script I am modifying... http://www.robertangle.com/MISC/ext_phorummail.php.txt It calls some other scripts in order to work. I added a hook so that another module would be called to turn around and email the post out. I figure it gets recorded to the database with those \n markings in them, and then when called to display on the web, nl2br is used to add line breaks. But I am trying to work it so that some forum members can participate via email. I labored hard the other day and figured it all out myself except for this last part. I just figure there would be a simple way to take $message or $new_message (found around line 400) and process it so that \n that shows up in the emails would be real line breaks instead. - Bob Quote Link to comment https://forums.phpfreaks.com/topic/203326-converting-n-into-real-line-breaks-in-email-messages/#findComment-1065714 Share on other sites More sharing options...
Dismal_Bliss Posted June 1, 2010 Author Share Posted June 1, 2010 I read somewhere to replace \n with \r\n and so I added this... $new_message ['body'] = str_replace("\n", "\r\n", $new_message ['body']); and now the \r\n appears in the email as well. This is driving me mad. I just want it to appear in email correctly. Quote Link to comment https://forums.phpfreaks.com/topic/203326-converting-n-into-real-line-breaks-in-email-messages/#findComment-1066112 Share on other sites More sharing options...
shadiadiph Posted June 1, 2010 Share Posted June 1, 2010 I did this before when I sent a message and saved it to the database I had to use $message= strip_tags($message); And when retrieving it to read [code $message = nl2br($message); [/code] Quote Link to comment https://forums.phpfreaks.com/topic/203326-converting-n-into-real-line-breaks-in-email-messages/#findComment-1066135 Share on other sites More sharing options...
Dismal_Bliss Posted June 1, 2010 Author Share Posted June 1, 2010 I did this before when I sent a message and saved it to the database I had to use $message= strip_tags($message); And when retrieving it to read $message = nl2br($message); Well, I can give that a shot. I was under the impression that was for converting \n to <br> for display in an html document. I'll report back. Quote Link to comment https://forums.phpfreaks.com/topic/203326-converting-n-into-real-line-breaks-in-email-messages/#findComment-1066138 Share on other sites More sharing options...
BizLab Posted June 1, 2010 Share Posted June 1, 2010 is there any reason you don't want to use an HTML email? Quote Link to comment https://forums.phpfreaks.com/topic/203326-converting-n-into-real-line-breaks-in-email-messages/#findComment-1066139 Share on other sites More sharing options...
shadiadiph Posted June 1, 2010 Share Posted June 1, 2010 Sorry I just went through my message script This is exactly what I used for inserting it $message = $_POST['message']; $message = trim($message); $message = stripslashes($message); $message =mysql_real_escape_string($message); And when calling it it to view was formatted exactly this way $message= $row["message"]; $message = nl2br($message); $message = stripslashes($message); And when calling the message to reply sorry $message= $row["message"]; $message = stripslashes($message); $message= strip_tags($message); Quote Link to comment https://forums.phpfreaks.com/topic/203326-converting-n-into-real-line-breaks-in-email-messages/#findComment-1066149 Share on other sites More sharing options...
Dismal_Bliss Posted June 1, 2010 Author Share Posted June 1, 2010 I added code so that the script would send me an email every step of the way with the original email body, and figure out between which steps it was getting all screwed up, which was when it was being writ to the database. So I copied the body and then overwritten was was returned from that function before sending the email and it all works now!!! // BOB MODIFICATION: Let's create a copy of the body before saving to the database, because aftwards it get's too screwed up for mailing. $body_for_mailing = $new_message ["body"]; // Save to database. $success = phorum_db_post_message ( $new_message ); // BOB MODIFICATION: Now let's restore the original body over the one just returned from saving to the database. $new_message ["body"] = $body_for_mailing; Quote Link to comment https://forums.phpfreaks.com/topic/203326-converting-n-into-real-line-breaks-in-email-messages/#findComment-1066234 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.