这是我的表单中的html代码。该文件名为interested.html
<h1 id="title5">Write Me</h1>
<p align="center" style="font-size:20px">If you would like to get in touch with me, please do!</p>
<form method="post" action="contact.php">
<fieldset>
<input name="name" type="text" placeholder="Full Name">
<input name="email" type="email" placeholder="Email Address">
<textarea name="msg" placeholder="Your message..."></textarea>
</fieldset>
<input type="submit" class="Send">
</form>
这是我的PHP代码。填写完表格后,我想显示我的感谢页面(send.html),而不是这个页面。此文件名为contact.php
<?php
//redirect to thank you page
//if information is not entered properly send to error page
//submit an confirmation email to me
$name = $_POST["name"];
$email = $_POST["email"];
$msg = $_POST["msg"];
echo "<pre>";
$email_body = "";
$email_body .= "Name " . $name . "'n";
$email_body .= "Email " . $email . "'n";
$email_body .= "Message " . $msg . "'n";
echo $email_body;
echo "</pre>";
header("location:sent.html");
?>
请帮忙,如果我没有很好地解释我的问题,或者是否需要更多信息,请告诉我。
提前感谢!
在返回任何内容之前,必须调用Header指令。但是你在header
之前写echo
。
尝试
<?php
ob_start();
//redirect to thank you page
//if information is not entered properly send to error page
//submit an confirmation email to me
$name = $_POST["name"];
$email = $_POST["email"];
$msg = $_POST["msg"];
echo "<pre>";
$email_body = "";
$email_body .= "Name " . $name . "'n";
$email_body .= "Email " . $email . "'n";
$email_body .= "Message " . $msg . "'n";
echo $email_body;
echo "</pre>";
header("location:sent.html");
?>