darrelf Posted April 28, 2011 Share Posted April 28, 2011 I have created a simple form that collects a comment or question from a visitor to my website. The problem is that if the visitor types: Your site looks Ok. I will get that message. But if the type: Your site needs "Work". I will get: Your site needs The script will not send the double quotes or anything after the double quotes What am I missing??? I have tried: addslashes() str_replace() preg_replace() with on change to the message. This is the script <?php $recipient = $_POST['recipient']; $subject = $_POST['subject']; $first_name = $_POST['first_name']; $last_name = $_POST['last_name']; $senders_email_address = $_POST['senders_email_address']; $comments = $_POST['comments']; $mailheaders .= "To: Thin Dime Web. <$recipient>\n"; $mailheaders .= "From: $first_name $last_name <$senders_email_address>\n"; $body .= "Subject: $subject\n\n"; $body .= "Senders Name: $first_name $last_name\n"; $body .= "E-mail Address: $senders_email_address\n\n"; $body .= "The following Comments or Question came from a visitor to your website\n"; $body .= "\n"; $body .= "$comments\n"; mail("$recipient", "$subject", "$body", "$mailheaders"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/235016-how-to-receive-messages-with-double-quotes-in-place/ Share on other sites More sharing options...
Maq Posted April 28, 2011 Share Posted April 28, 2011 In the future, please use tags around your code. Quote Link to comment https://forums.phpfreaks.com/topic/235016-how-to-receive-messages-with-double-quotes-in-place/#findComment-1207827 Share on other sites More sharing options...
JKG Posted April 28, 2011 Share Posted April 28, 2011 mysql_real_escape_string($_POST['']) might do the trick. Quote Link to comment https://forums.phpfreaks.com/topic/235016-how-to-receive-messages-with-double-quotes-in-place/#findComment-1207836 Share on other sites More sharing options...
wildteen88 Posted April 28, 2011 Share Posted April 28, 2011 mysql_real_escape_string($_POST['']) might do the trick. Why would the OP need to use that function if they are not using a database! @darrelf If you echo $comments variable just before you send the email does it show the message in full? $comments = $_POST['comments']; // preview comments echo $comments; Quote Link to comment https://forums.phpfreaks.com/topic/235016-how-to-receive-messages-with-double-quotes-in-place/#findComment-1207872 Share on other sites More sharing options...
darrelf Posted April 28, 2011 Author Share Posted April 28, 2011 mysql_real_escape_string($_POST['']) might do the trick. Why would the OP need to use that function if they are not using a database! @darrelf If you echo $comments variable just before you send the email does it show the message in full? $comments = $_POST['comments']; // preview comments echo $comments; No the message will not show double quotes if I place an echo statement. Quote Link to comment https://forums.phpfreaks.com/topic/235016-how-to-receive-messages-with-double-quotes-in-place/#findComment-1207910 Share on other sites More sharing options...
fugix Posted April 28, 2011 Share Posted April 28, 2011 You could try using htmlentities() Quote Link to comment https://forums.phpfreaks.com/topic/235016-how-to-receive-messages-with-double-quotes-in-place/#findComment-1207940 Share on other sites More sharing options...
JKG Posted April 29, 2011 Share Posted April 29, 2011 i thought mysql_real_escape_string() would backslash all the quotation marks, just a work around... sorry. Quote Link to comment https://forums.phpfreaks.com/topic/235016-how-to-receive-messages-with-double-quotes-in-place/#findComment-1208075 Share on other sites More sharing options...
wildteen88 Posted April 29, 2011 Share Posted April 29, 2011 i thought mysql_real_escape_string() would backslash all the quotation marks, just a work around... sorry. It escapes harmful characters to prevent SQL injection attacks within an SQL query. There is no point in using that function if the data is not going to a database. Quote Link to comment https://forums.phpfreaks.com/topic/235016-how-to-receive-messages-with-double-quotes-in-place/#findComment-1208077 Share on other sites More sharing options...
JKG Posted April 29, 2011 Share Posted April 29, 2011 thanks for the lesson. Quote Link to comment https://forums.phpfreaks.com/topic/235016-how-to-receive-messages-with-double-quotes-in-place/#findComment-1208079 Share on other sites More sharing options...
Muddy_Funster Posted April 29, 2011 Share Posted April 29, 2011 What do you get back if you do a print_r($_POST['comments'] Quote Link to comment https://forums.phpfreaks.com/topic/235016-how-to-receive-messages-with-double-quotes-in-place/#findComment-1208090 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.