0

我正在测试一个 PHP 邮件表单,一个非常简单的表单,在这里可以找到

<?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 = 'mymail@mail.com';

        $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: webmaster@mysite.com";





        $message = "Name: ".$contactname."\n";

        $message .= "Adress: ".$adress."\n";

        $message .= "E-mail: ".$contactemail."\n";

        $message .= "Message: ".$textmessage."\n";



        mail($to, $subject, $message, $headers);

    }

?>

问题是我每次在邮件中写单引号或双引号时都会收到不需要的斜杠“\”,因此“I'm”在我的邮箱中显示为“I\'m”。

我知道这与 PHP 区分代码引号和讲座引号的方式有关,但我不知道在我的表单中添加什么以使其正常运行。

任何帮助表示赞赏,

4

2 回答 2

5

最简单的做法是在 php.ini 中关闭魔术引号,

magic_quotes_gpc=false

如果你不能这样做,你需要像这样删除斜线,

if (get_magic_quotes_gpc()) {
    foreach($_POST as $k => $v) {
       $_POST[$k] = stripslashes($v);
    }
}
于 2010-04-28T01:06:40.333 回答
3

您可以尝试删除您的消息,例如:

$message = stripslashes($message);
于 2010-04-28T01:06:46.030 回答