title: recaptcha v2 not getting the "success"
body: <p>I’m having trouble in the implementation of recaptcha v2 chekbox. I first implemented in my form and it only works in local server. After failing in many attempts I search for some code and I’m using it raw from the tutorial and keep getting error. 
  Url: <a href="https://afrumex.com/google_reCAPTCHA/prueba.html" rel="nofollow noreferrer">https://afrumex.com/google_reCAPTCHA/prueba.html</a>
  Hope someone could help. Thanks!!</p>
  
  <p>HTML</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang="en"&gt;
  &lt;head&gt;
  &lt;meta charset="UTF-8"&gt;
  &lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&gt;
  &lt;meta http-equiv="X-UA-Compatible" content="ie=edge"&gt;
  &lt;title&gt;Ajax Contact Form&lt;/title&gt;
   &lt;link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"&gt;
  &lt;script src="https://www.google.com/recaptcha/api.js"&gt;&lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
   &lt;!-- ajax contact form --&gt;
  &lt;section style="margin-top: 50px;"&gt;
      &lt;div class="container"&gt;
          &lt;div class="row justify-content-center"&gt;
              &lt;div class="col-md-8"&gt;
                  &lt;div class="card"&gt;
                      &lt;h5 class="card-header"&gt;Ajax Contact Form&lt;/h5&gt;
                      &lt;div class="card-body"&gt;
                          &lt;form class="contact__form" method="post" action="mail.php"&gt;
  
                              &lt;!-- form message --&gt;
                              &lt;div class="row"&gt;
                                  &lt;div class="col-12"&gt;
                                      &lt;div class="contact__msg" style="display: none"&gt;
                                          &lt;p&gt;Your message was sent successfully.&lt;/p&gt;
                                      &lt;/div&gt;
                                  &lt;/div&gt;
                              &lt;/div&gt;
                              &lt;!-- end message --&gt;
  
                              &lt;!-- form element --&gt;
                              &lt;div class="row"&gt;
                                  &lt;div class="col-md-6 form-group"&gt;
                                      &lt;input name="name" type="text" class="form-control" placeholder="Name" required&gt;
                                  &lt;/div&gt;
                                  &lt;div class="col-md-6 form-group"&gt;
                                      &lt;input name="email" type="email" class="form-control" placeholder="Email" required&gt;
                                  &lt;/div&gt;
                                  &lt;div class="col-md-6 form-group"&gt;
                                      &lt;input name="phone" type="text" class="form-control" placeholder="Phone" required&gt;
                                  &lt;/div&gt;
                                  &lt;div class="col-md-6 form-group"&gt;
                                      &lt;input name="subject" type="text" class="form-control" placeholder="Subject" required&gt;
                                  &lt;/div&gt;
                                  &lt;div class="col-12 form-group"&gt;
                                      &lt;textarea name="message" class="form-control" rows="3" placeholder="Message" required&gt;&lt;/textarea&gt;
                                  &lt;/div&gt;
                                  &lt;div class="col-12 form-group"&gt;
  
                                      &lt;div class="g-recaptcha" data-sitekey="my site key here"&gt;&lt;/div&gt;
                                  &lt;/div&gt;
                                  &lt;div class="col-12"&gt;
                                      &lt;input name="submit" type="submit" class="btn btn-success" value="Send Message"&gt;
                                  &lt;/div&gt;
                              &lt;/div&gt;
                              &lt;!-- end form element --&gt;
                          &lt;/form&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
   &lt;/section&gt;
   &lt;script src="https://code.jquery.com/jquery-3.2.1.min.js"&gt;&lt;/script&gt;
   &lt;script src="main.js"&gt;&lt;/script&gt;
   &lt;/body&gt;
   &lt;/html&gt;
  </code></pre>
  
  <p>PHP</p>
  
  <pre><code>&lt;?php
  
  if ($_SERVER["REQUEST_METHOD"] == "POST") {
  
      // access
      $secretKey = 'my secret key here';
      $captcha = $_POST['g-recaptcha-response'];
  
      if(!$captcha){
        echo '&lt;p class="alert alert-warning"&gt;Please check the the captcha form1.&lt;/p&gt;';
        exit;
      }
  
      # FIX: Replace this email with recipient email
      $mail_to = "demo@gmail.com";
  
      # Sender Data
      $subject = trim($_POST["subject"]);
      $name = str_replace(array("\r","\n"),array(" "," ") , strip_tags(trim($_POST["name"])));
      $email = filter_var(trim($_POST["email"]), FILTER_SANITIZE_EMAIL);
      $phone = trim($_POST["phone"]);
      $message = trim($_POST["message"]);
  
      if ( empty($name) OR !filter_var($email, FILTER_VALIDATE_EMAIL) OR empty($phone) OR empty($subject) OR empty($message)) {
          # Set a 400 (bad request) response code and exit.
          http_response_code(400);
          echo '&lt;p class="alert alert-warning"&gt;Please complete the form and try again.&lt;/p&gt;';
          exit;
      }
  
      $ip = $_SERVER['REMOTE_ADDR'];
      $response=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=$secretKey&amp;response=$captcha&amp;remoteip=$ip");
      $responseKeys = json_decode($response,true);
  
      if(intval($responseKeys["success"]) !== 1) {
        echo '&lt;p class="alert alert-warning"&gt;Please check the the captcha form2.&lt;/p&gt;';
      } else {
          # Mail Content
          $content = "Name: $name\n";
          $content .= "Email: $email\n\n";
          $content .= "Phone: $phone\n";
          $content .= "Message:\n$message\n";
  
          # email headers.
          $headers = "From: $name &lt;$email&gt;";
  
          # Send the email.
          $success = mail($mail_to, $subject, $content, $headers);
          if ($success) {
              # Set a 200 (okay) response code.
              http_response_code(200);
              echo '&lt;p class="alert alert-success"&gt;Thank You! Your message has been sent.&lt;/p&gt;';
          } else {
              # Set a 500 (internal server error) response code.
              http_response_code(500);
              echo '&lt;p class="alert alert-warning"&gt;Oops! Something went wrong, we couldnt send your message.&lt;/p&gt;';
          }
      }
  
  } else {
      # Not a POST request, set a 403 (forbidden) response code.
      http_response_code(403);
      echo '&lt;p class="alert alert-warning"&gt;There was a problem with your submission, please try again.&lt;/p&gt;';
  }
  </code></pre>
  
  <p>?></p>