PHP Form with recaptcha

I am working on a php with recaptcha and I have no idea on what I am doing, as complete newbie with php. My forms semmed to work before but now they are throwing up errrors. The error is on the if (!$resp->is_valid) lines right now.
[php]

<?php session_start(); require_once('recaptchalib.php'); $privatekey = "removed"; $resp = recaptcha_check_answer ($privatekey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]); $username = $_POST['name']; $useremail = $_POST['email']; $recipient = "removed"; $subject = "Website Form"; $redirect = "../thankyou.html"; if (!$resp->is_valid) { $_SESSION['mess'] = "Invalid CAPTCHA"; header("Location: http://www.puddypaws.co.uk/phps/contacts.php"); } else { } $message = " ================================ Name: $username Email: $useremail ----------------------------------------- $fmessage ================================ "; $extraheaders = "From: $useremail\n\nReply-To: $useremail\n\n"; if (! mail($recipient, $subject, $message, $extraheaders)) echo "Mail did not send for some reason."; header("Location".$redirect); ?> [/php]

I am using the simplest form at this stage just to get the recaptcha to work, but I want to be able to get it validated in the future. Can anyone help on why I am getting errors?

Your code seems perfect and I can’t think of any possible reasons why you’re getting such error aside from, maybe, wrong private key…

Btw, try to double check if you’ve properly initialized the captcha in your form. Your form should have this line of code:

[php]recaptcha_get_html($publickey);[/php]

Thanks for your respose.
In my recaptchalib.php I have this code which seems to address what you suggested
[php]function recaptcha_get_html ($pubkey, $error = null, $use_ssl = false)
{
if ($pubkey == null || $pubkey == ‘’) {
die (“To use reCAPTCHA you must get an API key from https://www.google.com/recaptcha/admin/create”);
}

[/php]

and on the contact form page,
[php]<?php
require_once(‘recaptchalib.php’);
$publickey = “”;
echo recaptcha_get_html($publickey, $error);
?>
[/php]

so I guess I have initialised it, but I am having problems with getting errors on submit. And on other forms with the message bit. Does the message bit look good to you? Not sure what else to do from here.

I wonder also why the contact form has an extra f and if this mattered?

Sponsor our Newsletter | Privacy Policy | Terms of Service