Jump to content

Recommended Posts

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

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

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.

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.

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);

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;

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.