Jump to content

Problems with line breaks.


elmas156

Recommended Posts

Here's the code that I have:

 

<?php
if (get_magic_quotes_gpc()) {

function undoMagicQuotes($array, $topLevel=true) {

        $newArray = array();

		foreach($array as $key => $value) {

			if (!$topLevel) {

				$key = stripslashes($key);

			}
			if (is_array($value)) {

				$newArray[$key] = undoMagicQuotes($value, false);

			} else {

                $newArray[$key] = stripslashes($value);

			}

		}

		return $newArray;
    }

    $_GET = undoMagicQuotes($_GET);
    $_POST = undoMagicQuotes($_POST);
    $_COOKIE = undoMagicQuotes($_COOKIE);
    $_REQUEST = undoMagicQuotes($_REQUEST);

}



function safe($value){
   	return mysql_real_escape_string($value);
} 

$subject1 = "It's just a test.";
$message1 =                               // $subject1 and message1 are actually submitted from a form on the page...
"Here's a test.                           // so this section would really be $subject = safe($_POST['subject']); same w/ message
                                          // I did it this way to simplify... I'm pretty sure it would be the same either way.
Thanks,
Me";  // this is what is typed in the text area of the form.

$subject = safe($subject1);
$message = safe($message1);

?>

 

When these variables are mailed using php mail(), they display like this:

 

Subject: It\'s just a test.

Message: Here\'s a test.\r\n\r\nThanks,\r\nMe

 

When they are inserted into a database, they are inserted correctly, as they were typed.  My question is this: Is there a way to mail these and have them display correctly?  Should I just insert them into the database, then select them again to mail?  Thanks for any help.

Link to comment
https://forums.phpfreaks.com/topic/231617-problems-with-line-breaks/
Share on other sites

Yes, I should have posted this originally, but here is the actual mail function that I'm using:

 


$subject2 = nl2br("$subject");
		$message2 = nl2br("$message");
		$sendto1 = "$email";
		$emailsubject1 = "Message Sent";		
		$emailmessage1 = "<html>
		<body>
		<table width=\"500\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
		<tr>
		<td>
		This message is to notify you that you have been contacted through the messaging system.  A copy of the message has been included below.</p>
		<strong>Subject: \"$subject12\"</strong>
		<p>$message2</p>
		<hr width=\"500\" /><br />
		Thank you!
		</td>
		</tr>
		</table>
		</body>
		</html>";

		// To send HTML mail, the Content-type header must be set
		$headers1  = 'MIME-Version: 1.0' . "\r\n";
		$headers1 .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

		// Additional headers

		$headers1 .= 'From: CaresAbout.us <[email protected]>' . "\r\n";

		// Tells the mail server who the email is from				
		$fromaddress1 = '[email protected]';

		// Mail it
		mail($sendto1, $emailsubject1, $emailmessage1, $headers1, $fromaddress1);

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.