簡體   English   中英

無法將我的 php 頁面重定向到我的 html 謝謝頁面。 我究竟做錯了什么?

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

這是我的表單的 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>

這是我的 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"); ?>

請幫忙,如果我沒有很好地解釋我的問題或者需要更多信息,請告訴我。

提前致謝!

必須在返回任何內容之前調用標頭指令。 但是你在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");

?>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM