我在使用有限的PHP知识设置recaptha时遇到了一些麻烦。我已经设法让它在本质上工作,但我发现知道我的表单数据没有提交。
以下是PHP:
<?php
$sendToEmail="my@emailaddress.co.uk";
$yourname = $_POST["yourname"];
$timecall = $_POST["timecall"];
$email=$_POST["email"];
$phone=$_POST["phone"];
$message=$_POST["message"];
$content = "Time to Call : " . $timecall . "<br>";
$content .= "Name : " . $yourname . "<br>";
$content .= "Email : " . $email . "<br>";
$content .= "Phone : " . $phone . "<br>";
$content .= "Message : ". $message ."<br>";
$senderEmailId = "Reply-To: $email";
$senderEmailId = "From: $email\r\n";
$senderEmailId .= "Content-type: text/html\r\n";
$subject ="New Enquiry from the website";
if(isset($_POST['ContactButton'])) {
$url = 'https://www.google.com/recaptcha/api/siteverify';
$privatekey = "--private-key--";
$response = file_get_contents($url."?secret=".$privatekey."&response=".$_POST[g-recaptcha-response]."&remoteip=".$_SERVER['REMOTE_ADDR']);
$data = json_decode($response);
if (isset($data->success) AND $data->success==true) {
//// True- what happens when user is verified
header("Location:thankyou.php?CaptchaPass=True");
}else{
header("Location:thankyou.php?CaptchaFail=True");
}
}
?>
提前谢谢!
答案 0 :(得分:1)
PHP 101:未引用的数组键字符串被视为未定义的常量。你有:
$_POST[g-recaptcha-response]
被解析/执行为
$_POST[g minus recaptcha minus response]
$_POST[0 minus 0 minus 0]
$_POST[0]
如果您启用了PHP的调试选项(error_reporting
,display_errors
),则会收到有关此问题的警告。首先,这些设置不应该在调试/开发服务器上关闭。
尝试
$_POST['g-recaptcha-response']
^--------------------^
代替。请注意引号。