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
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 <support@CaresAbout.us>' . "\r\n";

		// Tells the mail server who the email is from				
		$fromaddress1 = '-fsupport@caresabout.us';

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

Link to comment
Share on other sites

But I am using the variables in a mysql query.  I'm inserting the data, then sending the user, and administrators an email with the same data.  That's how I know that it inserts properly into the database but not in an email.

Link to comment
Share on other sites

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.