I have a contact form at http://www.kaimeramedia.com/derek/Website/contact.php .I checked my PHP code at PHPcodechecker.com and it says there are no syntax errors. I think the beginning code is working in some manor because every time I press submit it makes it to the next validation where I am left with: "Improper email address detected. Please hit your browser back button and try again".
I just want to know if I should be writing the code differently to make sure the email validation goes through and allow the message to be submitted. I'm Not sure if I have something coded backwards. I tried many combinations, but as it stands this is the farthest I have come without a mailform.php error. The code for the mailform.php file is:
<?php
session_start();
$dontsendemail = 0;
$possiblespam = FALSE;
$strlenmessage = "";
$email = $_REQUEST['email'];
$name = $_REQUEST['name'];
$message = $_REQUEST['message'];
$subject = "Regarding Your Portfolio";$emailaddress = "[email protected]";
// checks if name field is empty
function checkname() {
if (empty($name)) {
die ("You did not enter your name. Please hit your browser back button and try again.");
return 1;
}
}
// checks if the captcha is input correctly
function checkcaptcha() {
if ($_SESSION["pass"] != $_POST["userpass"]) {
die("Sorry, you failed the CAPTCHA. Note that the CAPTCHA is case-sensitive. Please hit your browser back button and try again.");
return 1;
}
}
// checks proper syntax
function checkemail() {
if(preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/", $email));
else{
die("Improper email address detected. Please hit your browser back button and try again.");
return 1;
}
}
function spamcheck($field) {
if(eregi("to:",$field) || eregi("cc:",$field) || eregi("\r",$field) || eregi("\n",$field) || eregi("%0A",$field)){
$possiblespam = TRUE;
}else $possiblespam = FALSE;
if ($possiblespam) {
die("Possible spam attempt detected. If this is not the case, please edit the content of the contact form and try again.");
return 1;
}
}
function strlencheck($field,$minlength,$whichfieldresponse) {
if (strlen($field) < $minlength){
die($whichfieldresponse);
return 1;
}
}
if ($dontsendemail == 0) $dontsendemail = checkcaptcha($email);
if ($dontsendemail == 0) $dontsendemail = checkemail($email);
if ($dontsendemail == 0) $dontsendemail = spamcheck($email);
if ($dontsendemail == 0) $dontsendemail = spamcheck($name);
if ($dontsendemail == 0) $dontsendemail = strlencheck($email,10,"The email address field is too short. Please hit your browser back button and check your entry.<br />");
if ($dontsendemail == 0) $dontsendemail = strlencheck($message,10,"The message field is too short. Please hit your browser back button and check your entry.<br />");
if ($dontsendemail == 0) $dontsendemail = strlencheck($emailaddress,8,"You have not selected a recipient of your message. Please hit your browser back button and check your entry.<br />");
if ($dontsendemail == 0) $dontsendemail = strlencheck($name,3,"The Name field is too short. Please hit your browser back button and check your entry.<br />");
if ($dontsendemail == 0) {mail($emailaddress,"Subject: $subject",$message,"From: $name,$email" ); include "thankyou.php";}
?>
I put a dummy email in this code, but the real one is in the mailform.php file If anyone can see where I went wrong it would be of greatly appreciated.