I have a problem with Recaptcha V2.0 always returning false or bool(false). It feels like it doesn't validate through the right keys, but I have quadruple checked the domains I added and the keys I am using in my code. Maybe I've just done something wrong code wise.
The HTML form:
<form method="post" action="/php/emailCode.php">
Your Name <label><input type="text" name="name"></label>
<br/>
Email Address <label><input type="text" name="email"></label>
<br/>
Message <label><textarea name="message"></textarea></label>
<br />
<div id="captcha" data-sitekey="xxxxxxxxxxxxxxxxxxxxxxx"></div>
<br />
<input id="submitButton" type="submit">
</form>
<script src="https://www.google.com/recaptcha/api.js?onload=onloadCallback&render=explicit" async defer></script>
The PHP:
<?php
if(isset($_POST['g-recaptcha-response']) && $_POST['g-recaptcha-response']){
$secret = "xxxxxxxxxxxxxxxxxx";
$ip = $_SERVER['REMOTE_ADDR'];
$captcha = $_POST['g-recaptcha-response'];
$rsp = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=" . $secret . "&response=" . $captcha . "&remoteip=" . $ip);
var_dump($rsp);
$arr = json_decode($rsp);
if($arr->success === true){
$EmailFrom = "example@example.com";
$EmailTo = "example@gmail.com";
$Subject = $_POST['email'];
$Name = $_POST['name'];
$Message = $_POST['message'];
// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $Message;
$Body .= "\n";
// send email
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
}else{
echo 'Failure';
}
}
Also in the head I run this:
<script type="text/javascript">
var onloadCallback = function() {
grecaptcha.render('captcha', {
'sitekey' : 'xxxxxxxxxxxxxxxxxxxxxx'
});
};
</script>
I literally have no clue why it would return false. Thank you for your help in advance!