What are common pitfalls when adding reCAPTCHA to a PHP contact form?

One common pitfall when adding reCAPTCHA to a PHP contact form is not verifying the reCAPTCHA response correctly before processing the form submission. To solve this issue, you need to validate the reCAPTCHA response using the Google reCAPTCHA API before allowing the form to be submitted.

<?php
// Your reCAPTCHA secret key
$secret = 'YOUR_RECAPTCHA_SECRET_KEY';

// Verify reCAPTCHA response
$response = $_POST['g-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) {
    // Process the form submission
    // Your code to handle the form data goes here
} else {
    // Display an error message or redirect back to the form with an error
    echo 'reCAPTCHA verification failed. Please try again.';
}
?>