这是exmaple代码,您可以根据需要进行更改
把这个放进你的HTML
<INPUT class="input" type="text" name="vercode" value="" required>
<img src="captcha.php" style="margin:3px 0px; width:110px; height:34px">
创建Captcha文件
captcha.php<?php
session_start();
$text = rand(10000,99999);
$_SESSION["vercode"] = $text;
$image = imagecreatefromjpeg("images/bg.jpg");
$txtColor = imagecolorallocate($image, 0, 0, 0);
imagestring($image, 5, 5, 5, $text, $txtColor);
header("Content-type: image/jpeg");
imagejpeg($image);
?>
然后使用此代码
<?php
session_start();
if ($_POST["vercode"] != $_SESSION["vercode"] OR $_SESSION["vercode"]==\'\') {
echo \'<strong>Incorrect verification code...</strong>\';
}
else
{
$name = $_POST[\'name\'];
$phone = $_POST[\'phone\'];
$email = $_POST[\'email\'];
$location = $_POST[\'location\'];
$purpose = $_POST[\'purpose\'];
$status = $_POST[\'status\'];
$findus = $_POST[\'findus\'];
$inquiry = $_POST[\'inquiry\'];
$from = "JT Design";
$to = "inquiry@jtdesign.my";
$subject = "$from, $name has submitted the enquiry form.";
$message = "Hi $from,\\n$name has submitted the enquiry form. Details are as follow: \\n\\n/*** Form Details Begin ***/\\n\\nName: $name\\nPhone Number: $phone\\nEmail Address: $email\\nLocation: $location\\nContact Purpose: $purpose\\nHouse Status: $status\\nHow did visitor find us?: $findus\\nMessage: $inquiry\\n\\n/*** Form Details Ended ***/\\n\\nPlease response to $name as soon as possible.\\n\\nRegards,\\n$from";
if ($security=="17") {
mail($to, $subject, $message, "From: JTDesiGn");
header("Location:/thanks.php");
}
else {
header("Location:/enquiry-form/?Submission=failed");
}
}
?>