全部, 我在我的頁面上有一個表單,用於發送電子郵件。在表單頁面我有以下代碼:使用reCaptcha後防止電子郵件垃圾郵件
<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驗證做甚至提交。不知何故,我仍然收到空白的電子郵件通過。有誰知道我可以做什麼來防止垃圾郵件/空白電子郵件?我想我應該檢查後端的變量,以確保它們不是空白的,但是除非有一些值,否則表單甚至不應該被提交,所以我需要在初始頁面上有效的電子郵件地址。任何想法表示讚賞!
謝謝!
我建議你不要通過迴應錯誤甚至調用一個輸入字段來通知「垃圾郵件」*「請填寫我」* –
你總是可以動態地添加一個JS給兩個字段的特殊值,形成DOM創建時間和提交時間,而不是使用PHP檢查和評估這些字段之間的時間差。垃圾郵件通常很快。人類不是。 –