我正在测试一个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);
}
?>
Run Code Online (Sandbox Code Playgroud)
问题是我每次在邮件中写一个单引号或双引号时都会收到一个不需要的斜杠"\",所以"我"在我的邮箱中显示为"我是".
我知道这与PHP区分代码引用仅仅是讲座引号的方式有关,但我不知道在我的表单中添加什么以使其正常运行.
任何帮助表示赞赏,
最简单的方法是在php.ini中关闭魔术引号,
magic_quotes_gpc的= FALSE
如果你不能这样做,你需要删除这样的斜杠,
if (get_magic_quotes_gpc()) {
foreach($_POST as $k => $v) {
$_POST[$k] = stripslashes($v);
}
}
Run Code Online (Sandbox Code Playgroud)