使用reCaptcha后阻止电子邮件垃圾邮件

时间:2013-01-02 15:32:28

标签: 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="fill_me_out" id="fill_me_out">
<input type="button" value="Send" id="submit_contact_form_button">

第一个文本框是lamecaptcha,我在PHP端检查它以确保它没有填写。我还用一些JS隐藏它:

jQuery(function(){
    jQuery("#fill_me_out").hide();
});

然后,在我的页面使用jQuery验证器提交之前,我有以下表单验证:

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验证才能提交。不知怎的,我仍然收到空白的电子邮件。有没有人知道我可以做些什么来防止垃圾邮件/空白电子邮件?我在想我应该检查后端的变量以确保它们不是空白但是除非有一些值,否则甚至不应该提交表单,所以我需要在初始页面上有效的电子邮件地址。任何想法都表示赞赏!

谢谢!

1 个答案:

答案 0 :(得分:1)

只是因为你有一个提交按钮通过jQuery工作,并不意味着表单不能以其他方式提交。

spambot可能会检查表单的HTML,查看不同的字段,然后发送带有相关信息的POST请求。它不会评估你的jQuery。

如果您想要执行此类操作,请设置表单action="javascript:;",然后在提交之前将jQuery中的表单更新为实际值。