Page 1 of 1

\r\n issues with html mail

Posted: Thu Oct 06, 2011 9:42 am
by lubber123
Can anyone tell me why my code still sends me \r\n in my html emails or point me to a reference in how to format my code properly so that I don't get horrible emails.

Code: Select all

$message = "
								<html>
								<head>
								  <title>Faithbook Communication</title>
								  <style>
								  	#body{ background-color:#efefef; font:12px Arial, Helvetica, sans-serif; color:#003366; }
									.heading{ margin: 0em 0em 1em 0; width:400px; font:bold arial, helvetica; }
									#message{ margin: 3em 3em 3em 0; width:400px background-color:#fff; }
									.headers{ color:#336699; margin:-.3em 0 0 0; font:11px; }
									#footer{ background-image:url(http://www.lfmi.org/image/blue1_no_background.png); background-repeat:no-repeat; font:11px Arial, Helvetica, sans-serif;
										color:#333; text-align:right; width:100%; height:100px; margin: 1em 0 0 1em; }	
									h1{ font: bold 16px Arial, Helvetica, sans-serif; color:#003366; margin: 0 0 14px; }						
								  </style>
								</head>
								<body id='body'>
								  <h1>Living Faith Training Center</h1>
						 <p class='heading'>" . stripslashes($subject) . "</p>
						 <p class='headers'>To:" . $name . "</p>
						<p class='headers'>From: " . $sender . "<br />
						<p id='message'>" .nl2br($_POST['myReply']) . "</p>  ///I HAVE TRIED EVERYTHING HERE  STR_REPLACE included
								  <div id='footer'&nbsp;</div>;
								</body>
								</html>";
								
								
				 //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 .= 'To: <' . $to . '>' . "\r\n";
					$headers .= 'From: ' . $sender . ' <email@lfmi.org>' . "\r\n";

Re: \r\n issues with html mail

Posted: Thu Oct 06, 2011 3:20 pm
by twinedev
So is it the whole e-mail that has them or just what youa re wanting to put in <p id='message'> </p> that has them?

If you get this within the next hour, send me one at test001@sharklasers.com (it is a temp e-mail which will expire after 2 hours)

-Greg

Re: \r\n issues with html mail

Posted: Thu Oct 06, 2011 3:40 pm
by twinedev
I meant use the script to send me an e-mail so I could see the results, but as it ends up can't do a view source on e-mail through that system....

Trying to determine what you are getting compared to what you are wanting to get.

-Greg

Re: \r\n issues with html mail

Posted: Thu Oct 06, 2011 6:29 pm
by Eric!
To continue what greg was asking...is your problem with nl2br($_POST['myReply']) coming through with \r\n or the whole message?

Re: \r\n issues with html mail

Posted: Fri Oct 07, 2011 10:47 am
by lubber123
Not the whole message just the nl2br($_POST['myReply']) part.

here are the results from an email I sent to myself:

You have a new Faithbook message sent to you by Sean Lubbe,

Subject: dfgdfg

This is line onernThis is line twornThis is line 3
(THESE SHOULD BE ON SEPERATE LINES)

Re: \r\n issues with html mail

Posted: Fri Oct 07, 2011 6:32 pm
by Eric!
So what does $_POST['myReply'] look like before you try to send it? Var_dump() it and before you pass it to nl2br and after and you might see the problem.

Re: \r\n issues with html mail

Posted: Mon Oct 10, 2011 11:33 am
by lubber123
I have found the issue but have further problems:

This is what I am attempting to do:
1. I have to capture the text from the form textarea
2. Insert it into a DB
3. mail the text to a recipient

Okay so this is what I have found:
1. I cannot use nl2br or even str_replace to create the lines if I have done my sql prep first
2. If I send it first and then do the mysql_prep it changes the text and the second recipient gets the \r\n

Here is what the first recipient sees:
/////////////////
This is my testing
Here is line 1
Here is line 2

There was a line skipped
//////////////

This is what the second recipient sees:
////////////
This is my testing
Here is line 1\r\nHere is line 2\r\n\r\nThere was a line skipped
//////////////

The code for mysql_prep is below
Question: How can I reverse this each time considering I have to send this text to multiple recipients in a while loop?

CODE FOR MYSQL_PREP
$magic_quotes_active = get_magic_quotes_gpc();
$new_enough_php = function_exists( "mysql_real_escape_string" ); // i.e. PHP >= v4.3.0
if( $new_enough_php ) { // PHP v4.3.0 or higher
// undo any magic quote effects so mysql_real_escape_string can do the work
if( $magic_quotes_active ) { $value = stripslashes( $value ); }
$value = mysql_real_escape_string( $value );
} else { // before PHP v4.3.0
// if magic quotes aren't already on then add slashes manually
if( !$magic_quotes_active ) { $value = addslashes( $value ); }
// if magic quotes are active, then the slashes already exist
}
return $value;