Hi guys, I have a feeling there's something small I'm missing from this code. I'm trying to add captcha to an existing contact form that I use. The captcha image displays fine, but regardless of what I enter, the email gets sents and I'm redirected to my thank you page. Any ideas on where it's going wrong?

<?php session_start(); 

$to = 'myemail' ;
$subject = 'Enquiry' ;

$name = $_POST['name'];
$email = $_POST['email'];
$telephone = $_POST['telephone'];
$message = $_POST['message'];
$headers = 'From: ' . $_POST [ "from" ] . PHP_EOL ;

include_once $_SERVER['DOCUMENT_ROOT'] . '/securimage/securimage.php'; 

$securimage = new Securimage();

if ($securimage->check($_POST['captcha_code']) == false) {
  // the code was incorrect
  // you should handle the error so that the form processor doesn't continue

  // or you can use the following code if there is no validation or you do not know how
  echo "The security code entered was incorrect.<br /><br />";
  echo "Please go <a href='javascript:history.go(-1)'>back</a> and try again.";
  exit;
}
else

{$totalmessage = "
		Name:		$name  \n
		Email:		$email  \n
		Telephone:	$telephone  \n
		Message:	$message \n";

mail ( $to , $subject , $totalmessage , $headers );
header('location: thankyou.htm');}

?>

Thank you

I think that you need to check the variables that are sent from the form module to make sure that it is actually receiving the result from the Captcha.

False alarm! Thanks for your reply, but it turns out I had stupidly forgot to change the form to use the new script. D'oh!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.