Tuesday, 17 September 2013

Contact page redirect issue

Contact page redirect issue

For some reason my contact page won't relocate to thanks.html. It just
stays at the contact page and the contact form disappears.
<?php
if (empty($_POST) === false) {
$errors = array();
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
if (empty($name) === true || empty($email) === true || empty($message) ===
true) {
$errors[] = 'Name, email, and message are required.';
} else {
if (filter_var($email, FILTER_VALIDATE_EMAIL) === false) {
$errors[] = 'Please enter a valad email address.';
}
}
if (empty($errors) === true) {
mail('joe@mydomain.com', 'Contact Form' ,'$message', 'From: ' . $email);
header('Location: thanks.html');
exit();
}
}
?>
Here is my code from the form as well.
<?php
if (empty($errors) === false) {
echo '<ul>';
foreach($errors as $error) {
echo '<li>', $error, '</li>';
}
echo '<ul>';
}
?>
</div>
<div id="content">
<form action="" method="post">
<p>
<label for="name">Name:</label><br />
<input type="text" name="name" id="name" <?php if (isset($_POST['name'])
=== true) { echo 'value="',
strip_tags($_POST['name']), '"'; } ?> />
</p>
<p>
<label for="email">Email:</label><br />
<input type="text" name="email" id="email" <?php if
(isset($_POST['email']) === true) { echo 'value="',
strip_tags($_POST['email']), '"'; } ?>/>
</p>
<p>
<label for="message">Message:</label><br />
<textarea name="message" id="message"><?php if (isset($_POST['message'])
=== true) { echo strip_tags($_POST['message']), ''; } ?></textarea>
</p>
<p>
<input type="submit" />
</p>
</form>
</div>
Anyone have a quick fix for this? It's driving me crazy. I've been trying
different variations of these lines in the code above but nothing is
working...
if (empty($errors) === true) {
mail('joe@mydomain.com', 'Contact Form' ,'$message', 'From: ' . $email);
header('Location: thanks.html');
exit();

No comments:

Post a Comment