Add simple captcha to contact form

Hi, I have a very simple contact form, here is the code:

<?php

$my_email = "email@email.com";

$continue = "/";

$errors = array();

// Remove $_COOKIE elements from $_REQUEST.

if(count($_COOKIE)){foreach(array_keys($_COOKIE) as $value){unset($_REQUEST[$value]);}}

// Build message.

function build_message($request_input){if(!isset($message_output)){$message_output ="";}if(!is_array($request_input)){$message_output = $request_input;}else{foreach($request_input as $key => $value){if(!empty($value)){if(!is_numeric($key)){$message_output .= str_replace("_"," ",ucfirst($key)).": ".build_message($value).PHP_EOL.PHP_EOL;}else{$message_output .= build_message($value).", ";}}}}return rtrim($message_output,", ");}

$message = build_message($_REQUEST);

$message = stripslashes($message);

$subject = "General Enquiry";

$subject = stripslashes($subject);

$from_Name = "";

if(isset($_REQUEST['Name']) && !empty($_REQUEST['Name'])){$from_Name = stripslashes($_REQUEST['Name']);}

$headers = "From: {$from_Name} <{$_REQUEST['Email']}>";

mail($my_email,$subject,$message,$headers);

$message = "Thank you for your enquiry. We will be in touch with you as soon as possible.

Regards,

Website Name
http://www.domain.com/";

$subject = "General Enquiry";

$headers = "From: Website Name <noreply@domain.com>";

mail($_REQUEST['Email'],$subject,$message,$headers);

?>

I have tried implementing some free captchas but had no success, can anyone advise on a good solution?

Many thanks.

reCAPTCHA

That’s really good, but I was looking for the absolute most basic CAPTCHA, just a box you enter 4 digits into :slight_smile:

I have tried implementing some free captchas but had no success, can anyone advise on a good solution?

good solution of what? Any captcha script will need implementation. May be you need to improve your implementation skills, not another script to try.

That is very true - was just looking for advice on a simple captcha to implement, or a tutorial. :slight_smile:

It is quite hard, because captcha implementation requires general PHP programming skills - session handling, HTTP headers understanding.

May be you’d be statisfied with simple text field where user have to type current day of week for example. the field name should not reflect it’s purpose, name it something neutral, like “contact” or something

ReCAPTCHA is a good captcha to use, that has a good set of [url=“Installation Instructions”]installation instructions