elmas156 Posted March 24, 2011 Share Posted March 24, 2011 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 More sharing options...
will35010 Posted March 24, 2011 Share Posted March 24, 2011 I think you have to send headers to say it's an HTML message. Link to comment https://forums.phpfreaks.com/topic/231617-problems-with-line-breaks/#findComment-1191815 Share on other sites More sharing options...
will35010 Posted March 24, 2011 Share Posted March 24, 2011 Like so: // 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"; http://php.net/manual/en/function.mail.php Link to comment https://forums.phpfreaks.com/topic/231617-problems-with-line-breaks/#findComment-1191816 Share on other sites More sharing options...
elmas156 Posted March 24, 2011 Author Share Posted March 24, 2011 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); Link to comment https://forums.phpfreaks.com/topic/231617-problems-with-line-breaks/#findComment-1191820 Share on other sites More sharing options...
kenrbnsn Posted March 24, 2011 Share Posted March 24, 2011 You shouldn't be using the mysql_real_escape_string() function if you're not going to be using the variables in a mysql query. Ken Link to comment https://forums.phpfreaks.com/topic/231617-problems-with-line-breaks/#findComment-1191823 Share on other sites More sharing options...
Jahren Posted March 24, 2011 Share Posted March 24, 2011 mysql_real_escape_string() adds slashes to those characters to escape, you need not to worry about an email, it wont inject sql code Link to comment https://forums.phpfreaks.com/topic/231617-problems-with-line-breaks/#findComment-1191826 Share on other sites More sharing options...
elmas156 Posted March 24, 2011 Author Share Posted March 24, 2011 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 https://forums.phpfreaks.com/topic/231617-problems-with-line-breaks/#findComment-1191830 Share on other sites More sharing options...
kenrbnsn Posted March 24, 2011 Share Posted March 24, 2011 Send the email before you use the mysql_real_escape_function on the variables. That function puts the "\" characters into the values. Ken Link to comment https://forums.phpfreaks.com/topic/231617-problems-with-line-breaks/#findComment-1191837 Share on other sites More sharing options...
elmas156 Posted March 24, 2011 Author Share Posted March 24, 2011 I'll try it. Thanks. Link to comment https://forums.phpfreaks.com/topic/231617-problems-with-line-breaks/#findComment-1191839 Share on other sites More sharing options...
elmas156 Posted March 24, 2011 Author Share Posted March 24, 2011 Wow! It's amazing how something works when you do it right! Thanks for your help. Link to comment https://forums.phpfreaks.com/topic/231617-problems-with-line-breaks/#findComment-1191844 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.