<table bgcolor="#ECECEC" width="99%" border="1" cellspacing="1" cellpadding="3"><tr><td align="center">
<table width="100%"><tr>
<! -- START CONTACT FORM -- >
<form name="contactform" method="post" action="sendemail.php">
<td valign="top" align="right"><label for="name">NAME:</label></td>
<td valign="top"><input type="text" style="font-size:18px; font-family:serif; name="name" maxlength="50" size="40"></td>
</tr><tr>
<td valign="top" align="right"><label for="location">LOCATION:</label></td>
<td valign="top"><input type="text" style="font-size:18px; font-family:serif; name="location" maxlength="50" size="40"></td>
</tr><tr>
<td valign="top" align="right"><label for="email">EMAIL:</label></td>
<td valign="top"><input type="text" style="font-size:18px; font-family:serif; name="email" maxlength="50" size="40"></td>
</tr><tr>
<td valign="top" align="right"><label for="message">TEXT:</label></td>
<td valign="top"><textarea name="message" style="font-size:12px; font-family:verdana; width:500px;" maxlength="15000" cols="80" rows="20"></textarea></td>
</tr></table>
<table width="100%"><tr><td align="center" width="100%">
<font size="2" face="arial"><em>After writing your letter, double check your information, then click the check box below and press "SEND."</font><br />
<!-- RECAPTCHA BOX -->
<div class="g-recaptcha" data-sitekey="MY PUBLIC KEY IS HERE"></div>
<!-- SEND BUTTON -->
<input type="submit" value="SEND" style="height:50px; width:100px; font-size:18px; font-weight:bold; background-color:#aaffaa"></td>
</tr></table>
</form>
</td></tr></table>
<?php
function post_captcha($user_response) {
$fields_string = '';
$fields = array(
'secret' => 'MY SECRET KEY IS HERE',
'response' => $user_response
);
foreach($fields as $key=>$value)
$fields_string .= $key . '=' . $value . '&';
$fields_string = rtrim($fields_string, '&');
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, count($fields));
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, True);
$result = curl_exec($ch);
curl_close($ch);
return json_decode($result, true);
}
// Call the function post_captcha
$res = post_captcha($_POST['g-recaptcha-response']);
if (!$res['success']) {
// What happens when the CAPTCHA wasn't checked
echo '<p>Please go back and make sure you check the security CAPTCHA box.</p><br>';
} else {
// If CAPTCHA is successfully completed...
// Paste mail function or whatever else you want to happen here!
echo '<br><p>CAPTCHA was completed successfully!</p><br>';
}
?>
Why will recaptcha not recognize when I check the box?