简体   繁体   English

无法将我的 php 页面重定向到我的 html 谢谢页面。 我究竟做错了什么?

[英]Can't redirect my php page to my html thank you page. What am I doing wrong?

Here is my html code with my form.这是我的表单的 html 代码。 This file is named interested.html这个文件被命名为interesting.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>

This is my PHP code.这是我的 PHP 代码。 After the form is filled out I want my thank you page (sent.html) to show instead of this page.填写表格后,我希望显示我的感谢页面 (sent.html) 而不是此页面。 This file is named contact.php这个文件被命名为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"); ?>

Please help, and please let me know if I did not explain my question well enough or if more information is needed.请帮忙,如果我没有很好地解释我的问题或者需要更多信息,请告诉我。

Thanks in advance!提前致谢!

Header instruction must be called before any content returned.必须在返回任何内容之前调用标头指令。 But you write echo before header .但是你在header之前写了echo

Try尝试

<?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");

?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM