Jump to content


problem with text box in a form

  • Please log in to reply
1 reply to this topic

#1 hues

  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 10 May 2006 - 10:42 AM

I have used a simple coment form for a website.
Everything is working fine, except that if a field contains \ in the input, the mail I recieve shows up \\ instead of one backslash.
this is the part of the code

$message="$title $name $last_name\n$organization\n$mailingaddress\n$mailingaddress2\n$city $state $zip\n$phone\n$email_address\n$email_address2\n\n$comments\n";
if(mail($to,"Comments From NIA MPU",$message,"From: $email_address\n")) {
echo "Thanks for your comments.";
} else {
echo "There was a problem sending the mail. Please check that you filled in the form correctly.";

Someone suggested adding
$header .= "MIME-Version: 1.0rn";
$header .= "Content-Type: text/html; charset=iso-8859-1rn";

but still no help.

The form is working fine except this small problem, which the client has pointed out.

#2 wildteen88

  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 10 May 2006 - 02:31 PM

it is becuase you are using addslashes and so addslashes will ad an extraslash infront of another \ to so it preserves \ in the script, otherwise php will strip the \ out.

You might want to use stripslashes when sending the email or converr \'s into there html equivilent which is & #92; (without the space)

You can do this by doing this:
$message = str_replace("\\", "& #92;", $message);
That code converts a \ in to its html equivilent.
NOTE: before using the code above make sure you remove the space between the & and the #.

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users