Can you do decent validation with PHP? I have the following code in PHP for my form
PHP Code:
<?php
if(isset($_POST['submit'])) {
// define variables
$name = $_POST['name'];
$email = $_POST['email'];
$country = $_POST['country'];
$comment = $_POST['comment'];
// validation area
// email headers LINE 14
$headers .= "From: sitepage<email@email.com>\n"; $headers .= "X-Sender: <email@email.com>\n"; $headers .= "X-Mailer: PHP\n";
$headers .= "Return-Path: <email@email.com>\n";
$subject = "comments";
$emailbody = "
Name: $name
Email: $email
Country: $country
Comments: $comment
";
if(mail("email@email.com", $subject, $emailbody, $headers, "email@email.com")) {
$message = "<p>Your message was successfully sent</p>";
}
else
{
$message = "<p>Sorry, your message could not be sent right now</p>";
}
}
?>
Works fine, although this message appears after send:
"Notice: Undefined variable: headers in F:\users\0401213\httpdocs\gt1\contact.php on line 14"
But this has no validation so anyone can send spam over and over and over. I don't just want an email filter as it means spammers are still doing it, just I am not getting it taking up bandwidth and resources.
Is there a way to properly validate all fields in PHP and possibly use Captcha? I don't know much about captcha's, are thjey run in cgi script or from db's?