Page 1 of 1

Sending email: my ' come out as \'

Posted: Sat Feb 02, 2008 5:27 am
by enchance
This is probably a very simple problem but for all the mails I send through mail(), why do my ' always come out as \' ?

Here's the code I use which I made from scratch. Maybe you can tell me what's wrong with it:

Code: Select all

 
<?php
$myemail = "email@gmail.com";
$myname = "John Doe";
$sender = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$header =
"Recipient: $myname <$myemail>\n" .
"Subject: $subject\n" .
"From: $sender <$email>\n" .
"X-Mailer: PHP 4.x";
 
//send the mail + error messages
if(mail($myemail, $subject, $message, $header))
{
    $sender = rawurlencode($sender); //comes out as \\\\' so I guess I have to take this out
    Header("Location: http://domain.com/emailSent.php");
}
else
{
    Header("Location: http://domain.com/emailNotSent.php");
}
?>
 

Re: Sending email: my ' come out as \'

Posted: Sat Feb 02, 2008 6:29 am
by Chris Corbyn
Because your PHP installation has "magic_quotes" turned on. Turn it off if you can edit php.ini or use a .htaccess. Otherwise you're down to using stripslashes(), which plain sucks but will fix your problem.

Re: Sending email: my ' come out as \'

Posted: Mon Feb 04, 2008 9:20 pm
by enchance
Chris Corbyn wrote:Because your PHP installation has "magic_quotes" turned on. Turn it off if you can edit php.ini or use a .htaccess. Otherwise you're down to using stripslashes(), which plain sucks but will fix your problem.
Yes, I prefer .htaccess. What line/s do I add to disable magic_quotes?

Re: Sending email: my ' come out as \'

Posted: Tue Feb 05, 2008 12:40 am
by devendra-m
php_flag magic_quotes_gpc Off