<label>Anti-spam 10 + 12 =</label>
<input name="addition">
Form with Captcha (form information on previous page)
<form id="myForm" method="post" action="address.php">
<label>Subject</label>
<input type="text" name="subject" required>
<label>Name</label>
<input type="text" name="name" required>
<label>Email</label>
<input type="email" name="email" required>
<label>Your Comments</label>
<textarea type="text" name="comments" required> </textarea>
//include for anti-spam
<label>Anti-spam 10 + 12 =</label>
<input name="addition">
<input type="submit" name="submit" id="submit" value="SUBMIT" />
</form>
//added to match the input element in the form
$addition = $_POST['addition'];
$body = "From: $name\n E-Mail: $email\n Comments:\n $comments";
//make sure that you have the same name as that of the input element and the total for the addition
if ($_POST['submit'] && $addition == '22') {
//The information for mail and header is the same as before except it has been placed in the lf statement:
if (mail ($to, $subject, $body, $headers)) {
header( "Location: name.htm" );
//the next statement is to test your form
} else {
echo '<p>Something is incorrect, hit the back button and try again!</p>';
}
//this statement tests whether or not the user has the correct answer for the addition
} else if ($_POST['submit'] && $addition!= '22') {
echo '<p>You answered the anti-spam question incorrectly hit the back button and try again!</p>';
}
?>
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$comments= $_POST['comments'];
$headers = "From: $email \r\n";
$to = 'name@company.com';
$subject = 'subject line';
$addition = $_POST['addition'];
$body = "From: $name\n E-Mail: $email\n Comments:\n $comments";
if ($_POST['submit'] && $addition == '22') {
if (mail ($to, $subject, $body, $headers)) {
header( "Location:name.htm" );
} else {
echo 'Something is incorrect, hit the back button and try again!';
}
} else if ($_POST['submit'] && $addition!= '22') {
echo 'You answered the anti-spam question incorrectly hit the back button and try again!';
}
?>