How to add google captcha in PHP form

1- Generate reCAPTCHA API Keys

Register your website at – Google reCAPTCHA Admin console.

2- Get the site Key and secret Key:

  1. Site Key – This key is used in the HTML code of the reCAPTCHA.
  2. Secret Key – This key helps to authorize communication between your site and the reCAPTCHA server.

<script src='' async defer ></script>



  <meta charset="utf-8">
  <title>Google reCAPTCHA in PHP</title>
  <link rel="stylesheet" href="">


  <div class="container mt-5">
    <h2>Google reCAPTCHA in PHP Contact Form</h2>

    <!-- Contact form -->
    <form action="varify_captcha.php" name="contactForm" method="post" enctype="multipart/form-data">
      <div class="form-group">
        <input type="text" class="form-control" name="name" required>
      <div class="form-group">
        <input type="text" class="form-control" name="subject" required>

      <div class="form-group">
        <!-- Google reCAPTCHA block -->
        <div class="g-recaptcha" data-sitekey="6LfZ4AAVAAAAAFP6tyNYWgycDvXHIfjZg9shDZ05"></div>

      <div class="form-group">
        <input type="submit" name="send" value="Send" class="btn btn-primary btn-block">        

  <!-- Google reCaptcha -->
  <script src="" async defer></script>



        $secret = 'GOOGLE_CAPTACH_SECRET_KEY';
        $verifyResponse = file_get_contents(''.$secret.'&response='.$_POST['g-recaptcha-response']);
        $responseData = json_decode($verifyResponse);
            $message = "g-recaptcha varified successfully";
            $message = "Some error in vrifying g-recaptcha";
       echo $message;