I am bemused by this problem, I've run the php code through an online tester and there are no errors but when I click Submit without filling out any fields it just refreshes the page, no errors are displayed. When I complete the form and click Submit the same thing happens.
I think the html form etc is all good so now I'm stumped, any help is much appreciated.
<?php include ('./includes/header.php');?>
<?php
if (isset($_POST ['submit'])) {
$name = $_POST ['name'];
$email = $_POST ['email'];
$phone = $_POST ['phone'];
$message = $_POST ['message'];
$name = mysql_real_escape_string($name);
$email = mysql_real_escape_string($email);
$phone = mysql_real_escape_string($phone);
$message = mysql_real_escape_string($message);
$to = "example@gmail.com";
$subject = "Web Inquiry";
$body = "From: $name\n\n E-Mail: $email\n\n Telephone: $phone\n\n Message:\n\n $message";
$errors = array();
if (empty($name) || empty($email) || empty($messge)) {
if (empty($name)) {
$errors[] = "You must enter a name.";
}
if (strlen($name) > 50) {
$errors[] = "The maximum amount of characters for name is 50.";
}
if (empty($email)) {
$errors[] = "You must enter an email address.";
}
if (filter_var($register_email, FILTER_VALIDATE_EMAIL)===false) {
$errors [] = "Email address invalid.";
}
if (strlen($message) < 5) {
$errors [] = "Your messgae must be at least 25 characters.";
}
if (!empty($errors)) {
echo $errors;
} else {
// send message
mail($to, $subject, $body);
header('Location: message-sent.php');
exit();
//insert message into database
}
}
}
?>
<div id="form-wrap">
<form action="" method="post">
<fieldset>
<h2>Contact Form</h2>
<p>
Please complete the contact form and we will respond promptly to your enquiry.
</p>
<label class="red" for=""><em>*</em> required fields. </label>
<label><?php $errors['$name']; ?></label>
<label class="labelone" for="name"><em>*</em> Name </label>
<input name="name" placeholder="Minimum 2 characters" />
<label><?php $errors['$email']; ?></label>
<label for="email"><em>*</em> Email </label>
<input name="email" placeholder="doe@example.com"/>
<label><?php $errors['$phone']; ?></label>
<label for="phone"> <em> </em> Phone </label>
<input name="phone" placeholder="Please include country code if outside the U.S."/>
<label><?php $errors['$message']; ?></label>
<label for="message"> <em>*</em> Message </label>
<textarea name="message"> </textarea>
<input class="btn" type="submit" value="Submit" />
<input class="btn" type="reset" value="Reset" />
</fieldset>
</form>
</div>
<footer><?php include ('./includes/footer.php');?></footer>
</div><!-- /inner-wrapper -->
</div><!-- /outer-wrapper -->
</body>