Correctly encode characters in a PHP mail form ("I'm" turns to be "I\'m")
Posted
by Peanuts
on Stack Overflow
See other posts from Stack Overflow
or by Peanuts
Published on 2010-04-28T01:01:51Z
Indexed on
2010/04/28
1:13 UTC
Read the original article
Hit count: 324
Hello guys,
I'm testing a PHP mail form, a very barebones one, found here:
<?php
if(isset($_POST['submit']))
{
//The form has been submitted, prep a nice thank you message
$output = '<h3>Thanks for your message</h3>';
//Deal with the email
$to = '[email protected]';
$subject = 'you have a mail';
$contactname = strip_tags($_POST['contactname']);
$adress = strip_tags($_POST['adress']);
$contactemail = strip_tags($_POST['contactemail']);
$textmessage = strip_tags($_POST['textmessage']);
$boundary =md5(date('r', time()));
$headers = "From: My Site\r\nReply-To: [email protected]";
$message = "Name: ".$contactname."\n";
$message .= "Adress: ".$adress."\n";
$message .= "E-mail: ".$contactemail."\n";
$message .= "Message: ".$textmessage."\n";
mail($to, $subject, $message, $headers);
}
?>
The problem is I'm receiving an unwanted slash "\" everytime I write a single or a double quote in my message, so "I'm" appear as "I\'m" in my mailbox.
I know it have to do with the way PHP distinguishes code quotes from only lecture quotes, but I wouldn't know what to add in my form to get it properly running.
Any help is appreciated,
© Stack Overflow or respective owner