title: Google reCAPTCHA - keep getting `incorrect-captcha-sol`
body: <p>I am trying to add a reCAPTCHA to my site, but keep getting <code>incorrect-captcha-sol</code> error when I submit the answer.</p>
  <p>Can anyone tell me if I am correct in doing the following?</p>
  <p>I have a generic index.php, which includes contact.php. In contact.php I have inserted the following code:</p>
  <pre class="lang-php prettyprint-override"><code>require_once('recaptchalib.php');
  $publickey = &quot;XXXX&quot;;
  $privatekey = &quot;XXXX&quot;;
  
  //the response from reCAPTCHA
  $resp = null;
  //the error code from reCAPTCHA, if any
  $error = null;
  
  if ($_POST['submit']) {
      $message = $_POST['message_txt'];
      $name = $_POST['name_txt'];
      $email = $_POST['email_txt'];
      
      $emailBody = $message;
      $to = 'xx';
      $from = $name.' &lt;'.$email.'&gt;';
      $subject = 'XX Website Enquiry';
      $headers = 'From: '.$from;  
          
      $resp = recaptcha_check_answer($privatekey, $_SERVER[&quot;REMOTE_ADDR&quot;], $_POST[&quot;recaptcha_challenge_field&quot;], $_POST[&quot;recaptcha_response_field&quot;]);
      
      if ($resp-&gt;is_valid) {
          echo 'captcha correct';
          if (mail($to,$subject,$emailBody,$headers)) {
              //echo 'mail sent';
              $confirmation = 'sent';
          }
          else {
              //echo 'mail not sent';
              $confirmation = 'error';
          }
      } else {
          # set the error code so that we can display it. You could also use
          # die (&quot;reCAPTCHA failed&quot;), but using the error message is
          # more user friendly
          
          $error = $resp-&gt;error;
          
          echo $error;
      }
  }
  </code></pre>
  <p>In my html I inserted the CAPTCHA like this:</p>
  <pre class="lang-html prettyprint-override"><code>&lt;form name=&quot;contactForm&quot; method=&quot;post&quot; action=&quot;index.php?id=contact&amp;action=submit#contact&quot;&gt;
      &lt;tr&gt;&lt;td&gt;Name&lt;/td&gt;&lt;td&gt;&lt;div align=&quot;right&quot;&gt;
          &lt;input type=&quot;text&quot; name=&quot;name_txt&quot; class=&quot;input&quot;&gt;
          &lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
      &lt;tr&gt;&lt;td&gt;Email&lt;/td&gt;&lt;td&gt;&lt;div align=&quot;right&quot;&gt;
          &lt;input type=&quot;text&quot; name=&quot;email_txt&quot; class=&quot;input&quot;&gt;
      &lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
      &lt;tr&gt;&lt;td height=&quot;10&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
      &lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;Message&lt;/td&gt;&lt;/tr&gt;
      &lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&lt;textarea name=&quot;message_txt&quot; class=&quot;textarea&quot; style=&quot;width:200px; height:100px&quot;&gt;&lt;/textarea&gt;&lt;/td&gt;&lt;/tr&gt;
      &lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&lt;?php echo recaptcha_get_html($publickey, $error); ?&gt;&lt;/td&gt;&lt;/tr&gt;
      &lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;padding-top:10px;&quot;&gt;&lt;input type=&quot;image&quot; src=&quot;images/header_06.gif&quot; name=&quot;submit&quot; value=&quot;submit&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
  &lt;/form&gt;
  </code></pre>
  <p>I cannot see that I am doing anything wrong, but would appreciate any help.</p>