What could be causing the recaptcha always returning false in the PHP script?

The issue of reCAPTCHA always returning false in a PHP script could be due to incorrect configuration of the reCAPTCHA keys or the way the reCAPTCHA response is being validated in the PHP script. To solve this issue, ensure that the reCAPTCHA keys are correctly set up in the script and that the response from the reCAPTCHA API is being properly validated.

<?php
// Your secret key from Google reCAPTCHA
$secret = 'YOUR_SECRET_KEY';

// Response from reCAPTCHA
$response = $_POST['g-recaptcha-response'];

// Verify reCAPTCHA response
$verify = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret={$secret}&response={$response}");
$captcha_success = json_decode($verify);

if ($captcha_success->success) {
    // reCAPTCHA verification successful, proceed with your code
    echo "reCAPTCHA verification successful!";
} else {
    // reCAPTCHA verification failed, handle the error
    echo "reCAPTCHA verification failed!";
}
?>