Sending email: my ' come out as \'

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
enchance
Forum Commoner
Posts: 34
Joined: Sat Sep 15, 2007 12:10 pm

Sending email: my ' come out as \'

Post 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");
}
?>
 
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

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

Post 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.
enchance
Forum Commoner
Posts: 34
Joined: Sat Sep 15, 2007 12:10 pm

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

Post 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?
devendra-m
Forum Contributor
Posts: 111
Joined: Wed Sep 12, 2007 3:16 am

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

Post by devendra-m »

php_flag magic_quotes_gpc Off
Post Reply