我的reCaptcha没有验证。无论如何,它让我通过。它正在发送电子邮件并重定向到感谢页面,但没有验证reCaptcha。我错过了什么?这是我的PHP代码。我没有显示它,但我在head和form标签中有正确的代码(从reCAPTCHA复制/粘贴)。感谢您提前提供任何帮助。
<?php
if (isset($_POST['submit'])) {
$secret = 'MY SECRET KEY';
$response = $_POST['g-recaptcha-response'];
$remoteip = $_SERVER['REMOTE_ADDR'];
$url = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=$secret&response=$response&remoteip=$remoteip");
$result = json_decode($url, TRUE);
if ($result['success'] == 1){
}
}
if(isset($_POST['submit'])) {
$emailbody = 'Name: '.$_POST['name']."\n"
.'Phone: '.$_POST['phone']."\n"
.'Email: '.$_POST['email']."\n"
.'Message: '.$_POST['message'];
mail('myemail@mydomain.com', 'More Information', $emailbody);
header('location: thankyou.php');
exit();
}
?>
答案 0 :(得分:0)
您正在验证,但是,您在验证后正在处理,但在if语句之外,您确定验证是否成功...
此代码可以更改为:
<?php
if (isset($_POST['submit'])) {
$secret = 'MY SECRET KEY';
$response = $_POST['g-recaptcha-response'];
$remoteip = $_SERVER['REMOTE_ADDR'];
$url = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=$secret&response=$response&remoteip=$remoteip");
$result = json_decode($url, TRUE);
if ($result['success'] == 1){
$emailbody = 'Name: '.$_POST['name']."\n"
.'Phone: '.$_POST['phone']."\n"
.'Email: '.$_POST['email']."\n"
.'Message: '.$_POST['message'];
mail('myemail@mydomain.com', 'More Information', $emailbody);
header('location: thankyou.php');
exit();
} else {
// captcha failed
}
}
?>