title: reCAPTCHA and PHP to send an Email Form
body: <p>I'm using GoDaddy as my web server.</p>
  
  <p>I'm trying to implement reCAPTCHA into my email form for my website, however it seems to not be able to work.  That is, I pass the reCAPTCHA test but the email isn't sent.</p>
  
  <p>I've only used PHP and HTML for the site so far.</p>
  
  <p>I have also added the script to my head tag</p>
  
  <pre><code>&lt;script src='https://www.google.com/recaptcha/api.js'&gt;&lt;/script&gt;
  </code></pre>
  
  <p>Here are the code snippets.</p>
  
  <p>HTML:</p>
  
  <pre><code>&lt;form action="#" id="form" method="post" name="form"&gt;
        &lt;div class="form-group"&gt;
               &lt;label for="name-field"&gt;Name&lt;/label&gt;
               &lt;input name="vname" class="form-control" placeholder="Enter Your Full Name" type="text" value=""&gt;
        &lt;/div&gt;
        &lt;div class="form-group"&gt;
               &lt;label for="email-field"&gt;Email address&lt;/label&gt;
               &lt;input name="vemail" class="form-control" placeholder="Enter Your Email" type="text" value=""&gt;
        &lt;/div&gt;
        &lt;div class="form-group"&gt;
               &lt;label for="contract-field"&gt;Enter Contract Here&lt;/label&gt;
               &lt;textarea name="msg" class="form-control" placeholder="Enter Contract Here" rows="5"&gt;&lt;/textarea&gt;
        &lt;/div&gt;
        &lt;div class="g-recaptcha form-group" data-sitekey="SITEKEY"&gt;&lt;/div&gt;
        &lt;div class="form-group"&gt;&lt;button id="send" name="submit" type="submit" class="btn btn-default"&gt;Submit&lt;/button&gt;&lt;/div&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>PHP:</p>
  
  <pre><code>&lt;?php
  //Checking For reCAPTCHA
  $captcha;
  if(isset($_POST['g-recaptcha-response'])){
      $captcha=$_POST['g-recaptcha-response'];
  }
  // Checking For correct reCAPTCHA
  $response=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=SECRETKEY&amp;response=".$captcha."&amp;remoteip=".$_SERVER['REMOTE_ADDR']);
  if($response.success==false){
      echo "Your CAPTCHA response was wrong."
      exit;
  }
  else{
      // Checking For Blank Fields..
      if($_POST["vname"]==""||$_POST["vemail"]==""||$_POST["msg"]==""){
          echo "Fill All Fields..";
      }
      else{
          // Check if the "Sender's Email" input field is filled out
          $email=$_POST['vemail'];
          // Sanitize E-mail Address
          $email =filter_var($email, FILTER_SANITIZE_EMAIL);
          // Validate E-mail Address
          $email= filter_var($email, FILTER_VALIDATE_EMAIL);
          if (!$email){
              echo "Invalid Sender's Email";
          }
          else{
              $to = 'johdoe@example.com';
              $subject = 'Test';
              $message = $_POST['msg'];
              $headers = 'From:'. $email . "\r\n"; // Sender's Email
              // Message lines should not exceed 70 characters (PHP rule), so wrap it
              $message = wordwrap($message, 70, "\r\n");
              // Send Mail By PHP Mail Function
              mail($to, $subject, $message, $headers);
              echo "Your mail has been sent successfully!";
          }
      }
  } else {
      echo "Your CAPTCHA response was wrong.  Try again."
      exit;
  }?&gt;
  </code></pre>
  
  <p>Am I implementing server-side wrong?  Or is it client side?</p>