我希望 php 联系人在用户正确提交后重定向到感谢页面,但它没有,它说的就是这个
警告:无法修改标头信息 - 标头已由 ()
这是我的Thanks.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Thank you we will get back to you </title>
<meta content="php, contact, form, thinking" name="keywords">
<meta content="Great success!" name="description">
<style>
p {
font-family: Cambria, Cochin, serif;
font-size: large;
margin-bottom: -5px;
}
h1 {
font-family: "Trebuchet MS", Arial, sans-serif;
font-size: xx-large;
color: #3399FF;
}
body {
padding: 10px;
background-color: #F4F4F4;
}
</style>
</head>
<body>
<h1> </h1>
<h1>Thank You!</h1>
<p>We've received your request, we will get back to you soon.</p>
</body>
</html>
这是我的 php 它称为 mailer.php
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$number = $_POST['number'];
$message = $_POST['message'];
$from = 'From:you';
$to = 'me@hotmail.com';
$subject = 'Hello';
$human = $_POST['human'];
$body = "From: $name\n E-Mail: $email\n Number: $number\n Message:\n $message";
if ($_POST['submit']) {
if ($name != '' && $email != '') {
if ($human == '4') {
if (mail ($to, $subject, $body, $from)) {
echo '<p>Your message has been sent!</p>';
header("Location: thanks.html");
} else {
echo '<p>Something went wrong, go back and try again!</p>';
}
} else if ($_POST['submit'] && $human != '4') {
echo '<p>You answered the anti-spam question incorrectly!</p>';
}
} else {
echo '<p>You need to fill in all required fields!!</p>';
}
}
?>
这是我的contact.html 页面,只是表单部分。
<h1 class="contactcat">Contact us for </h1>
<form action="mailer.php" method="post">
<label>Name</label>
<input name="name" placeholder="Type Here">
<label>Email</label>
<input name="email" type="email" placeholder="Type Here">
<label>Contact Number</label>
<input name="number" type="text" placeholder="Type Here">
<label>Message</label>
<textarea name="message" placeholder="Type Here"></textarea>
<br/>
<label>What's 2+2 (type only the number)</label>
<input name="human" type="number" placeholder="Type Here">
<br/>
<input id="submit" name="submit" type="submit" value="Submit">
</form>