-3

在提交表单后,我需要一种简单的方法来重定向到感谢页面。

PHP:

<?php $name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$formcontent="From: $name \n Message: $message";
$recipient = "email@gmail.com";
$subject = "Contact Form";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!"; 
?>

我不想更改的 HTML:

<form action="mail.php" method="POST" autocomplete="on"></br>
    <p>Name:</p><input type="text" name="Name"  size="20"></br>
    <p>Email:</p><input type="text" name="email"  size="20"></br>
    <p>Message:</p>
    <textarea id="styled" type="textarea" name="message" form="input></textarea></br>
    <pre><input type="submit" value="Send"><input type="reset" value="Clear"></pre>
</form>
4

6 回答 6

2

您可以使用以下代码。您可以使用简单的 PHP 脚本将用户从他们输入的页面重定向到不同的网页。使用标题

<?php
  //your code goes here -> mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
  header( 'Location: http://www.yoursite.com/new_page.html' ) ;
?>
于 2013-02-11T10:37:43.177 回答
1

你可以试试 header("location: next_page.php"); 请注意,在此之前无法将任何内容打印到浏览器。

于 2013-02-11T10:37:58.140 回答
0

采用header

mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
header('Location : path_to_thank_you_page');
exit();
于 2013-02-11T10:37:22.140 回答
0

在 mail.php 的末尾添加一个标题,将您重定向到感谢页面。例子

header("Location: thankyou.php");
于 2013-02-11T10:38:30.953 回答
0

采用header(Location:"yorpage".php);

给出文件的相对路径。不要在 header 语句之前添加任何 php 语句。

于 2014-04-09T10:39:52.070 回答
0

您可以在 index.php 中重命名您的 index.html。然后在 index.php 中包含 mail.php。在 index.php 上提交重定向后

<?php include('mail.php'); ?>

<form action="<?= $_SERVER['PHP_SELF'];?>" method="POST" autocomplete="on"></br>
于 2018-03-24T14:07:54.217 回答