如何在提交PHP电子邮件表单后重定向到HTML页面?

时间:2013-10-11 19:51:44

标签: php html forms email post

这是我的代码:

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

我只需要知道如何在单击提交后重定向到HTML页面并确保脚本发送电子邮件。任何帮助将不胜感激!

4 个答案:

答案 0 :(得分:2)

将其添加到脚本的末尾:

header("Location: URL");

其中URL是您要重定向到的网页的网址。

答案 1 :(得分:0)

PHP

header('Location: login.php?msg=1');

的javascript

<script> window.location='forgot.php'</script>";

HTML

<META HTTP-EQUIV="REFRESH" CONTENT="3;URL=http://google.com">

答案 2 :(得分:0)

您可能错过了开放表单和关闭表单,或者只是包含它

 <form name="PL" action="newForm.php" method="post">
 <?php
 $name = $_POST['name'];  
 $email = $_POST['email'];

 $subject = $_POST['subject'];

 $message = $_POST['message'];

 $formcontent = "From: $name \n Email: $email \n Subject: $subject \n Message:   
 $message";

 $recipient = "hunter@dreaminginhd.com";

 $subject = "Contact Form";

 $mailheader = "From: $email \r\n";

 mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");  
include "newForm2.php";
 ?>
 <input type="submit" name="btn_submit" value="Display Invoice" /> 
 </form>

答案 3 :(得分:0)

首先,我们将mailto函数与localhost和电子邮件客户端一起使用:
 在stackoverflow上检查此链接:
网址链接:send email to owner by collecting information provided by user through form?

然后我推荐使用Swiftmailer。 http://swiftmailer.org/docs/sending.html他们获得了最好的手册。