如何在PHP中保护联系表单

时间:2015-02-05 07:20:11

标签: php

我不精通php,有人可以提供一个很好的强大代码,我可以为我的表单量身定制,以防止注入我的脚本吗?我需要确切知道在现有代码中插入此代码的确切位置。

我的代码如下。我没有打开和结束php标签,所以所有的代码都可见。

$name=addslashes($_POST['name']);
$email=addslashes($_POST['email']);
$website=addslashes($_POST['website']);
$services=addslashes($_POST['services']);
$comments=addslashes($_POST['message']);

// you can specify which email you want your contact form to be emailed to here

$toemail = "email@domainname.com"; $subject = "Creative Design Consultation Request";

$headers = "MIME-Version: 1.0\n" ."From: \"".$name."\" <".$email.">\n" ."Content-type: text/html; charset=iso-8859-1\n";

$body = "Name: ".$name."\n"
."Email: ".$email."\n"
."Website: ".$website."\n"
."Services: ".$services."\n"
."Comments:\n".$comments;

mail($toemail, $subject, $body, $headers);
echo "Thank you for submitting your request";

1 个答案:

答案 0 :(得分:1)

这可能是您正在寻找的:
Sanitize filters php