由于某种原因,我的联系页面不会重新定位到Thanks.html。它只是停留在联系页面上,联系表格消失了。
<?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();
}
}
?>
这也是我表单中的代码。
<?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>
有人对此有快速解决方法吗?这让我疯狂。我一直在上面的代码中尝试这些行的不同变体,但没有任何效果......
if (empty($errors) === true) {
mail('joe@mydomain.com', 'Contact Form' ,'$message', 'From: ' . $email);
header('Location: thanks.html');
exit();