遇到ReCaptcha问题。即使选中了复选框,它仍会返回false。我已经三次检查我的钥匙,很高兴他们是正确的。我正在使用基于在我的另一个网站上成功使用的代码。看不出有什么问题。
为便于参考,我复制了所有相关的编码。希望有人会马上看到我做错了什么。
表格代码:
<form name="contactform" method="post" action="send_form_email.php">
<table width="450px">
<tr>
<td valign="top">
<label for="first_name">First Name *</label>
</td>
<td valign="top">
<input type="text" name="first_name" placeholder="Please enter your first name" maxlength="50" size="30">
</td>
</tr>
<tr>
<td valign="top"">
<label for="last_name">Last Name *</label>
</td>
<td valign="top">
<input type="text" name="last_name" placeholder="Please enter your surname" maxlength="50" size="30">
</td>
</tr>
<tr>
<td valign="top">
<label for="email">Email Address *</label>
</td>
<td valign="top">
<input type="email" name="email" placeholder="Please enter your email address" maxlength="80" size="30">
</td>
</tr>
<tr>
<td valign="top">
<label for="telephone">Telephone Number</label>
</td>
<td valign="top">
<input type="tel" name="telephone" placeholder="Please enter your phone number" maxlength="30" size="30">
</td>
</tr>
<tr>
<td valign="top">
<label for="comments">Comments *</label>
</td>
<td valign="top">
<textarea name="comments" maxlength="1000" cols="25" rows="6"></textarea>
</td>
</tr>
<tr>
<td colspan="2" style="text-align:center"><div class="g-recaptcha" data-sitekey="6LejdlwUAAAAAHb5qaNIhfDzxL1i9a9sCyw8dLzD"></div></td>
</tr>
<tr>
<td colspan="2" style="text-align:center">
<input type="submit" value="Submit"> <br> <a href="https://www.freecontactform.com/email_form.php" class="visuallyhidden">Email Form</a>
</td>
</tr>
</table>
</form>
PHP代码:
<?php
// Code from ReCaptcha evaluation:
$email;$comment;$captcha;
if(isset($_POST['email'])){
$email=$_POST['email'];
}if(isset($_POST['comment'])){
$email=$_POST['comment'];
}if(isset($_POST['g-recaptcha-response'])){
$captcha=$_POST['g-recaptcha-response'];
}
if(!$captcha){
echo '<h2>Please check the the captcha form.</h2>';
exit;
}
$secretKey = "************************************";
$ip = $_SERVER['REMOTE_ADDR'];
$response=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".$secretKey."&response=".$captcha."&remoteip=".$ip);
$responseKeys = json_decode($response,true);
if(intval($responseKeys["success"]) !== 1) {
echo '<h2>You are a spammer ! Your form has been rejected.</h2>';
} else
// End Code from ReCaptcha evaluation.
非常感谢 添