Php 使用reCaptcha后防止电子邮件垃圾邮件
全部,, 我的网页上有一张表格,我用它来发送电子邮件。在表单页面上,我有以下代码:Php 使用reCaptcha后防止电子邮件垃圾邮件,php,jquery,Php,Jquery,全部,, 我的网页上有一张表格,我用它来发送电子邮件。在表单页面上,我有以下代码: <input type="text" name="Name" id="your_name" class="contact_form_input_text"> <input type="text" name="Email_Address" id="your_email" class="contact_form_input_text"> <input type="text" name="
<input type="text" name="Name" id="your_name" class="contact_form_input_text">
<input type="text" name="Email_Address" id="your_email" class="contact_form_input_text">
<input type="text" name="fill_me_out" id="fill_me_out">
<input type="button" value="Send" id="submit_contact_form_button">
然后,在使用jQuery validator提交页面之前,我将进行以下表单验证:
jQuery("#contact_form").validate({
rules: {
Email_Address: {
required: true,
email: true
},
Name: {
required: true
}
},
messages: {
Email_Address: {
required: "Please enter an email address!",
email: "Please enter a valid email address!"
},
Name: {
required: "Please enter your Name!"
}
}
});
jQuery("#submit_contact_form_button").click(function(event) {
if (jQuery("#contact_form").valid()) {
challengeField = jQuery("input#recaptcha_challenge_field").val();
responseField = jQuery("input#recaptcha_response_field").val();
var html = jQuery.ajax({
type: "POST",
url: site_url + "ajax.recaptcha.php",
data: "recaptcha_challenge_field=" + challengeField + "&recaptcha_response_field=" + responseField,
async: false
}).responseText;
if(html == "success")
{
//$("#captchaStatus").html(" ");
// Uncomment the following line in your application
//return true;
jQuery("#contact_form").submit();
}else{
jQuery("#captchaStatus").html("Your captcha is incorrect. Please try again");
Recaptcha.reload();
return false;
}
}
return false;
});
如果所有内容都填写正确,则页面将提交。我有以下检查来检查蹩脚的验证码:
$lamecaptcha_check = $_POST['fill_me_out'];
if($lamecaptcha_check!=""){
echo '[box style="alert"]Why are you trying to spam us? It could be because you don\'t have Javascript enabled and filled out an incorrect box![/box]';
}else{
//Send the form using mail
}
提交表单是一个按钮,而不是提交,因此它必须经过jquery验证才能提交。不知怎的,我还是收到了一些空白邮件。有人知道我还能做些什么来防止垃圾邮件/空白电子邮件吗?我想我应该检查后端的变量,以确保它们不是空的,但表单甚至不应该提交,除非有一些值,所以我需要在初始页面上提供有效的电子邮件地址。任何想法都很感激
谢谢 仅仅因为您有一个提交按钮,就可以通过jQuery工作,这并不意味着表单不能以其他方式提交 spambot可能会检查表单的HTML,查看不同的字段,然后发送一个包含相关信息的POST请求。它不会评估jQuery
如果您想执行类似操作,请设置表单的
action=“javascript:;”
,然后在提交前在jQuery中将其更新为实际值。我建议您不要通过回显错误或甚至调用输入字段“请填写我”来通知“垃圾邮件”您的支票您总是可以使用JS向两个字段(表单DOM创建时间和提交时间)动态添加一个特殊值,然后使用PHP检查和计算这些字段之间的时间差。垃圾邮件通常很快。人类不是。谢谢你的想法。您可以使用jQuery控制操作属性字段,还是只更新文档中的操作属性字段。submit()?只需使用.attr()
进行设置。
$lamecaptcha_check = $_POST['fill_me_out'];
if($lamecaptcha_check!=""){
echo '[box style="alert"]Why are you trying to spam us? It could be because you don\'t have Javascript enabled and filled out an incorrect box![/box]';
}else{
//Send the form using mail
}