Skip to content Skip to sidebar Skip to footer

Google Recaptcha V2 (checkbox) Verification

I have a contact form which is working fine. I have Integrate Google ReCaptcha v2 with it and it is showing below my contact form but form will be submitted either user checked reC

Solution 1:

<?php
if (isset($_POST['g-recaptcha-response']) && !empty($_POST['g-recaptcha-response'])) {
    // Your site secret key obtained from Google
    $secret         = '#####################################';
    $grResponse     = $_POST['g-recaptcha-response'];
    // Verify with Google Servers
    $verifyResponse = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret=' . $secret . '&response=' . $grResponse);
    $responseData   = json_decode($verifyResponse);
    if ($responseData->success) {
        ob_start();
        $name    = $_POST['name'];
        $email   = $_POST['email'];
        $phone   = $_POST['phone'];
        $message = $_POST['message'];

        $email_from    = '';
        $email_subject = "Contact Form";
        $email_body    = "User Name: $name \n" . "User Email: $email \n" . "Phone Number: $phone \n" . "User Message: \n $message \n";

        $to = "my_Email_here";

        $headers = "From: $email_from \r\n";
        $headers = "Reply-To: $email \r\n";

        $result = mail($to, $email_subject, $email_body, $headers);

        if ($result) {
            echo "Sent Successfully";
        }

        else {
           echo "Something Went wrong. Please try again";
        }
    } else {
         echo "################################"; 
    }
} else {

       echo "################################"; 
} 
?>

Please check below code:


Post a Comment for "Google Recaptcha V2 (checkbox) Verification"