【问题标题】:Can't redirect my php page to my html thank you page. What am I doing wrong?无法将我的 php 页面重定向到我的 html 感谢页面。我究竟做错了什么?
【发布时间】:2016-03-24 07:32:55
【问题描述】:

这是我的表单的 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 代码。填写表格后,我希望显示我的感谢页面 (sent.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");

?>

请帮忙,如果我没有很好地解释我的问题或需要更多信息,请告诉我。

提前致谢!

【问题讨论】:

    标签: php html forms redirect


    【解决方案1】:

    必须在返回任何内容之前调用头指令。但是你在header之前写echo。

    【讨论】:

    • 我是个白痴。感谢您的快速回复,效果很好。 :)
    【解决方案2】:

    试试

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

    【讨论】:

    • 在本地主机上工作,但在我的 github.io 上不工作
    • 是github页面吗? github不支持php
    猜你喜欢
    • 1970-01-01
    • 2020-04-14
    • 2020-09-30
    • 2013-08-06
    • 1970-01-01
    • 2010-09-14
    • 1970-01-01
    • 1970-01-01
    • 2013-09-10
    相关资源
    最近更新 更多