There's still no javascript on that page.
There is invalid HTML in at least one place:
Code:
<form id="contact-form" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"/>
The form tag is not a self closing tag, but might be being partially closed by having that slash there. In any case, it can't do anything good, get rid of it.
As to the form being empty when submitted, that might have something to do with it.
But this is much more likely - Near the beginning there's:
Code:
//define variables and receiving email
$name=""; $email=""; $phone=""; $message="";
After that, no attempt is made to assign any values to those, yet they are used here:
Code:
<?php
if (isset($_POST["check"])) {
check_posts();
define("EMAIL", "mmmmmmm@gmail.com");
$header = "From: $email\n" . "Reply-To: $email\n";
$subject = "A message from the Contact Form";
$email_to = EMAIL;
$todayis = date("l, F j, Y, g:i a") ;
$emailMessage = "Name: " . $name . "\n";
$emailMessage .= "Email: " . $email . "\n";
$emailMessage .= "Phone: " . $phone . "\n";
$emailMessage .= "Date: " . $todayis . "\n\n";
$emailMessage .= "Message: " . $message;
mail($email_to, $subject, $emailMessage, $header );
}
?>
to send the message, so of course they're empty.
Missing is this (from a previous version I think):
PHP Code:
//assign post data to variables
$name = trim($_POST['name']);
$email = trim($_POST['email']);
$phone = trim($_POST['phone']);
$message = trim($_POST['message']);
It might be good to check if they're set before making those assignments, but I think you did that by checking if the form had been submitted or not, and it looks like you are doing that before validation. So that could go here:
Code:
<?php
if (isset($_POST["check"])) {
check_posts();
//assign post data to variables
$name = trim($_POST['name']);
$email = trim($_POST['email']);
$phone = trim($_POST['phone']);
$message = trim($_POST['message']);
define("EMAIL", "mmmmmmm@gmail.com");
$header = "From: $email\n" . "Reply-To: $email\n";
$subject = "A message from the Contact Form";
$email_to = EMAIL;
$todayis = date("l, F j, Y, g:i a") ;
$emailMessage = "Name: " . $name . "\n";
$emailMessage .= "Email: " . $email . "\n";
$emailMessage .= "Phone: " . $phone . "\n";
$emailMessage .= "Date: " . $todayis . "\n\n";
$emailMessage .= "Message: " . $message;
mail($email_to, $subject, $emailMessage, $header );
}
?>
With or without that though, it looks like the mail, such as it is, gets sent regardless of whether or not it passes the check_posts function.
You could have check_posts return true or false:
Code:
//validate form inputs
function check_posts() {
$found = array();
foreach ($_POST as $x => $y) {
if ($x == "check") break;
$conditions = array(
"name" => (strlen($y) < 5),
"phone" => (strlen($y) < 6),
"email" => (!filter_var($y, FILTER_VALIDATE_EMAIL)),
"message" => (strlen($y) < 10));
$errors = array(
"name" => "Valid Name ",
"phone" => "Valid phone only",
"email" => "Valid email only",
"message" => "Valid message only" );
if ($conditions[$x]) $found[] = $errors[$x];
}
$i = 1; if (count($found) > 0) {
foreach ($found as $z) { echo "<p>$i. $z</p>"; $i++; }
return false;
} else {
echo " Your message has been sent. ";
return true;
//end validation code
}
}
Then down here tie continued processing of the mail to that value:
Code:
<?php
if (isset($_POST["check"])) {
$mailApproved = check_posts();
if($mailApproved){
//assign post data to variables
$name = trim($_POST['name']);
$email = trim($_POST['email']);
$phone = trim($_POST['phone']);
$message = trim($_POST['message']);
define("EMAIL", "mmmmmmm@gmail.com");
$header = "From: $email\n" . "Reply-To: $email\n";
$subject = "A message from the Contact Form";
$email_to = EMAIL;
$todayis = date("l, F j, Y, g:i a") ;
$emailMessage = "Name: " . $name . "\n";
$emailMessage .= "Email: " . $email . "\n";
$emailMessage .= "Phone: " . $phone . "\n";
$emailMessage .= "Date: " . $todayis . "\n\n";
$emailMessage .= "Message: " . $message;
mail($email_to, $subject, $emailMessage, $header );
}
}
?>
Bookmarks