在成为大量垃圾邮件的目标后,我一直在尝试在我网站的 .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 似乎实际上并没有做任何事情。