Jump to content

Recommended Posts

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

$from="$email_address";
$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.
Link to comment
https://forums.phpfreaks.com/topic/9461-problem-with-text-box-in-a-form/
Share on other sites

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 [b]& #92;[/b] (without the space)

You can do this by doing this:
[code]$message = str_replace("\\", "& #92;", $message);[/code]
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 #.
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.