成为大量垃圾邮件的目标之后,我一直在尝试在网站的.php联系人表单上实施reCAPTCHA v2。我的表单前端正常工作,并且该表单的网站提交正常工作,但是我仍然收到垃圾邮件,并且来自Google reCAPTCHA管理员的警告是我的站点未在验证解决方案。
我浏览了其他已回答的问题,试图共同解决科学怪人的问题,但是我没有任何运气。我对.php不太熟悉,所以我不太了解我所做的更改会干扰其他人。
<?php
/* Verify reCAPTCHA First */
$secret = 'my secret code from Google';
$url = 'https://www.google.com/recaptcha/api/siteverify?secret='.$secret.'&response='.$_POST['g-recaptcha-response'];
$verifyresponse = file_get_contents($url);
$verify = json_decode($verifyresponse);
/* Process Form */
/* Make sure all fields are filled */
$errors = '';
if (empty($_POST['name']) ||
empty($_POST['email']) ||
empty($_POST['phone']) ||
empty($_POST['message'])) {
$errors .= "</br> Error: All fields are required";
}
$name = $_POST['name'];
$email_address = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];
/* Check for valid email adress */
if (!preg_match(
"/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i",
$email_address)){
$errors .= "</br> Error: Invalid email address";
}
/* No errors, then submit */
if ($verify->success = 'true' && empty($errors)) {
$to = "...@gmail.com"; // Emails to send the form to
$email_subject = "SLS Contact Form Submission: $name";
$email_body =
"New Contact Form. ".
"Here are the details: \n
Name: $name \n
Email: $email_address \n
Phone Number: $phone \n
Message: \n $message";
/* $message = "Name - " . $_POST['name'] . "<br>";
$message .= "Email - " . $_POST['email'] . "<br>";
$message .= "Phone - " . $POST['phone'] . "<br>";
$message .= "Message - " . $_POST['message'] . "<br>";
*/
$headers = "From ....com\n";
$headers .= "Reply to: $email_address";
mail($to, $email_subject, $email_body, $headers);
// Send mail OK
//redirect to the 'thank you' page
header('Location: ./thankyou.html');
exit;
}
else {
// Send mail error
$_POST['errors'] = $errors;
}
?>
联系表单提交,发送等,但是reCAPTCHA似乎并没有做任何事情。
答案 0 :(得分:0)
if ($verify->success = 'true'
将其设置为true。
您要使用==
,或者出于安全考虑,请使用=== true
。