Email form with Captcha help please
Posted: Wed Jan 14, 2009 5:09 am
Hi Guys,
new to php so have a basic understanding.
I've got the email sending and a redirect to the homepage. But I want a captcha for security. Ive got the image for the captcha displaying but not sure how I would make it work.
html captcha:
<img src="aaaacaptcha.php" style="display: block;margin-bottom: 5px;"/>
<input type="text" name="captcha2" id="captcha2" value="captcha2" />
code for the captcha image:
<?php
session_start();
$RandomStr = md5(microtime());
$ResultStr = substr($RandomStr,0,5);
$NewImage =imagecreatefromjpeg("img.jpg");
$LineColor = imagecolorallocate($NewImage,233,239,239);
$TextColor = imagecolorallocate($NewImage, 255, 255, 255);
imageline($NewImage,1,1,40,40,$LineColor);
imageline($NewImage,1,100,60,0,$LineColor);
imagestring($NewImage, 5, 20, 10, $ResultStr, $TextColor);
$_SESSION['captcha'] = $ResultStr;
header("Content-type: image/jpeg");
imagejpeg($NewImage);
?>
code for the email php:
<?php
if(isset($_POST['submit'])) {
$to = "my email address";
$subject = "web form";
$firstname = $_POST['first name'];
$lastname = $_POST['last name'];
$body = " email fields";
header("Location: homepage address");
mail($to, $subject, $body);
}
else
{
echo "Not Sent";
}
?>
Please help
new to php so have a basic understanding.
I've got the email sending and a redirect to the homepage. But I want a captcha for security. Ive got the image for the captcha displaying but not sure how I would make it work.
html captcha:
<img src="aaaacaptcha.php" style="display: block;margin-bottom: 5px;"/>
<input type="text" name="captcha2" id="captcha2" value="captcha2" />
code for the captcha image:
<?php
session_start();
$RandomStr = md5(microtime());
$ResultStr = substr($RandomStr,0,5);
$NewImage =imagecreatefromjpeg("img.jpg");
$LineColor = imagecolorallocate($NewImage,233,239,239);
$TextColor = imagecolorallocate($NewImage, 255, 255, 255);
imageline($NewImage,1,1,40,40,$LineColor);
imageline($NewImage,1,100,60,0,$LineColor);
imagestring($NewImage, 5, 20, 10, $ResultStr, $TextColor);
$_SESSION['captcha'] = $ResultStr;
header("Content-type: image/jpeg");
imagejpeg($NewImage);
?>
code for the email php:
<?php
if(isset($_POST['submit'])) {
$to = "my email address";
$subject = "web form";
$firstname = $_POST['first name'];
$lastname = $_POST['last name'];
$body = " email fields";
header("Location: homepage address");
mail($to, $subject, $body);
}
else
{
echo "Not Sent";
}
?>
Please help