Hi, I use a very basic PHP contact form, simple place text fields on the page with the form and then link to enquiry.php which has this code…
<?php
$my_email = "name@domain.co.uk";
$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.co.uk/";
$subject = "General Enquiry";
$headers = "From: Website Name <noreply@domain.co.uk>";
mail($_REQUEST['Email'],$subject,$message,$headers);
?>
I want to add a captcha to this. - I found a place with a verificationimage.php which generates 4 random number images.
http://www.lostmisfitdesign.com/verificationimage.php
<?php
// -----------------------------------------
// The Web Help .com
// -----------------------------------------
header('Content-type: image/jpeg');
$width = 50;
$height = 24;
$my_image = imagecreatetruecolor($width, $height);
imagefill($my_image, 0, 0, 0xFFFFFF);
// add noise
for ($c = 0; $c < 40; $c++){
$x = rand(0,$width-1);
$y = rand(0,$height-1);
imagesetpixel($my_image, $x, $y, 0x000000);
}
$x = rand(1,10);
$y = rand(1,10);
$rand_string = rand(1000,9999);
imagestring($my_image, 5, $x, $y, $rand_string, 0x000000);
setcookie('tntcon',(md5($rand_string).'a4xn'));
imagejpeg($my_image);
imagedestroy($my_image);
?>
How would I implement the captcha to the form? Any suggestions or tips would be much appreciated.
Thanking you