First, I am not a PHP coder. I found this email form example on the web.
I have been using this on my website for a few years now, but more and more I am getting spam emails.
The form does do some type of checking for spammers, but I have an issue that it does not cover.
One of the fields on my form is address, as in street address.
My question is, how can I check that field for a web address, and if it contains a web address, redirect the user to a page saying they've been blocked, or something to that effect?
This is my existing code:
<?php
// Grab the form vars
$name = (isset($_POST['name'])) ? $_POST['name'] : '' ;
$email = (isset($_POST['email'])) ? $_POST['email'] : '' ;
$address = (isset($_POST['address'])) ? $_POST['address'] : '' ;
$city = (isset($_POST['city'])) ? $_POST['city'] : '' ;
$state = (isset($_POST['state'])) ? $_POST['state'] : '' ;
$zip = (isset($_POST['zip'])) ? $_POST['zip'] : '' ;
$phone = (isset($_POST['phone'])) ? $_POST['phone'] : '' ;
$message = (isset($_POST['message'])) ? $_POST['message'] : '' ;
// POSTing check
if(!$_SERVER['REQUEST_METHOD'] == "POST"){
die("Something is wrong as you have not posted to this page");
exit;
}
// Check for email injection
if (has_emailheaders($email)) {
die("Possible email injection occuring");
}
// prepare email body text
$Body .= "";
$Body .= "Name: ";
$Body .= $name;
$Body .= "\n";
$Body .= "Address: ";
$Body .= $address;
$Body .= "\n";
$Body .= "City: ";
$Body .= $city;
$Body .= "\n";
$Body .= "State: ";
$Body .= $state;
$Body .= "\n";
$Body .= "Zip: ";
$Body .= $zip;
$Body .= "\n";
$Body .= "Phone: ";
$Body .= $phone;
$Body .= "\n";
$Body .= "Message: ";
$Body .= "\n";
$Body .= $message;
// mail(to,subject,message,headers,parameters)
$success = mail("myAddress@domain.com","From CompuTech.com website",$Body, "From: $email");
// redirect to success page
if ($success){
print "<meta http-equiv=\"refresh\" content=\"0;URL=ok.htm\">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}
function has_emailheaders($text) {
return preg_match("/(%0A|%0D|\n+|\r+)(content-type:|to:|cc:|bcc:)/i", $text);
}


