title: Google re-captcha not working in existing php form
body: <p>Please be patient, I'm new at this. :) I can't seem to get Google re-captcha to work in my existing php form - see below. I am sure I need to remove or add code. Also, I'd like the re-captcha to validate before submitting to my email. Thank you so much. </p>
  
  <pre><code>&lt;?php
  
  if(isset($_POST['g-recaptcha-response']) &amp;&amp; !empty($_POST['g-recaptcha-response'])):
  
      $secret = 'secret key';
      //get verify response data
      $verifyResponse = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret='.$secret.'&amp;response='.$_POST['g-recaptcha-response']);
      $responseData = json_decode($verifyResponse);
      if($responseData-&gt;success):
  
  
  //redirect if login was successful
  header('Location: ./xxxx.hmtl');
  
  $myemail = 'email@hotmail.com';
  if (isset($_POST['email'])) {
  $subject = $_POST['subject'];
  $email = $_POST['email'];
  $message = $_POST['message'];
  echo "Email:".$email."&lt;br&gt;";
  echo "Subject:".$subject."&lt;br&gt;";
  echo "Message:".$message."&lt;br&gt;";
  
  if ($_POST['subject'] ) { 
  echo 'Tastes Like Spam!'; }
  else {
  $success = true; mail($myemail);
  </code></pre>
  
  <p>}</p>
  
  <pre><code>$to = $myemail;
  $email_subject = "xxxx.com New Message: $subject";
  $email_body = "You have received a new message. ".
  " Details are below:\n Subject: $subject \n ".
  "Email: $email\n Message: \n $message";
  $headers = "From: $myemail\n";
  $headers .= "Reply-To: $email";
  mail($to,$email_subject,$email_body,$headers);
  </code></pre>
  
  <p>}</p>
  
  <p>?></p>
  
  <p>My html form code is below. I am not sure why it doesn't redirect to the home page nor submits the form. It goes to an error page - basically the .php url. Thanks for your help and being patient :)</p>
  
  <pre><code>    &lt;div class="section-container-spacer"&gt;
          &lt;form action="process.php" class="reveal-content" method="post" onsubmit="myFunction()"&gt;
            &lt;div class="row"&gt;
              &lt;div class="col-md-6"&gt;
                &lt;div class="form-group"&gt;
                  &lt;input type="text" name="email" class="form-control" id="email" placeholder="Email" required=""&gt;
                &lt;/div&gt;
                &lt;div class="form-group"&gt;
                  &lt;input type="text" name="subject" class="form-control" id="subject" placeholder="Subject" required=""&gt;
                &lt;/div&gt;
                &lt;div class="form-group"&gt;
                  &lt;textarea name="message" class="form-control" rows="3" id="message" placeholder="Enter your message" required=""&gt;&lt;/textarea&gt;
                &lt;/div&gt;
                  &lt;div class="form-group"&gt;&lt;div class="g-recaptcha" data-sitekey="site key goes here"&gt;&lt;/div&gt;&lt;/div&gt;
                &lt;button type="submit" class="btn btn-primary btn-lg"&gt;Send&lt;/button&gt;
              &lt;/div&gt;
              &lt;div class="col-md-6"&gt;
                &lt;ul class="list-unstyled address-container"&gt;
                  &lt;li&gt; &lt;span class="fa-icon"&gt; &lt;i class="fa fa-at" aria-hidden="true"&gt;&lt;/i&gt; &lt;/span&gt; &lt;a href="mailto:email@.hotmail.com"&gt;email@hotmail.com&lt;/a&gt; &lt;/li&gt;
                  &lt;li&gt; &lt;span class="fa-icon"&gt; &lt;i class="fa fa fa-map-marker" aria-hidden="true"&gt;&lt;/i&gt; &lt;/span&gt; Los Angeles, CA &lt;/li&gt;
                &lt;/ul&gt;
              &lt;/div&gt;
            &lt;/div&gt;
          &lt;/form&gt;
          &lt;script&gt;
  function myFunction() {
      alert("Your message has been sent. We will be in touch.");
  }
  &lt;/script&gt; 
          &lt;script type="text/javascript"&gt;
       $(document).ready(function () {
  $("input#submit").click(function(){
      $.ajax({
          type: "POST",
          url: "process.php",
          data: $('form.contact').serialize(),
          success: function(msg){
              $("#thanks").html(msg) 
          },
          error: function(){
              alert("failure");
          }
      });
  });
  });
    &lt;/script&gt; 
        &lt;/div&gt;
  </code></pre>