treehouse : what would you like to learn today?
Web Design Web Development iOS Development

Re-captcha is not working on Nicesimple contact form

  • I tried niceandsimple contact from this website, worked wonderful. But after getting so many spam mails, i decided to add recaptcha although I followed all instructions still its not working. Tutorial Link here is my website and here is code

      <form method="post" action="contactengine.php">
            <label for="Name">Name:</label>
            <input type="text" name="Name" id="Name" />
    
            <label for="Email">Email:</label>
            <input type="text" name="Email" id="Email" />
    
            <label for="Message">Message:</label><br />
            <textarea name="Message" rows="20" cols="20" id="Message"></textarea>
    
              >       
           <div id="captcha-area">
    
            <?php
    
            require_once('recaptchalib.php');
            $publickey = "6Ld9ltwSAAAAAKnB4ANn4baVx@@@@@@@@";
            $privatekey = "6Ld9ltwSAAAAAGa8lKr7QzaDD52M********";
    
            # the response from reCAPTCHA
            $resp = null;
            # the error code from reCAPTCHA, if any
            $error = null;
    
            # are we submitting the page?
            if ($_POST["submit"]) {
              $resp = recaptcha_check_answer ($privatekey,
                              $_SERVER["REMOTE_ADDR"],
                              $_POST["recaptcha_challenge_field"],
                              $_POST["recaptcha_response_field"]);
    
              if ($resp->is_valid) {
              echo "You got it!";
              # in a real application, you should send an email, create an account, etc
              } else {
              # set the error code so that we can display it. You could also use
              # die ("reCAPTCHA failed"), but using the error message is
              # more user friendly
              $error = $resp->error;
              }
            }
            echo recaptcha_get_html($publickey, $error);
            ?>
    
            </div>
    
            <input type="submit" name="submit" value="Submit" class="submit-button" />
          </form>