ユーザーが正しく送信した後、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>