显示新页面的联系表单然后返回主页?

时间:2013-11-08 20:01:25

标签: php html css forms

我的网站上有一个基本的联系表单,工作正常。提交虽然它打开一个空白页面,上面写着“谢谢”...我想打开一个风格化的网页,上面写着“提交成功”显示大约3秒钟,然后恢复到主页面。我对网页设计很新,特别是PHP,所以如果有人能提供任何可能很棒的提示。我把PHP代码放在下面:

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

2 个答案:

答案 0 :(得分:1)

尝试:

<?php 

$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$formcontent = "From: $name \r\n Message: $message";
$recipient = "myemail@email.com";
$mailheader = "From: $email \r\n";
mail($recipient, $message, $formcontent, $mailheader) or die("Error!");

?><!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="refresh" content="3; url=http://mysite.com/contact.php">
    </head>
    <body>
       <p>Submitted successfully</p>
    </body>
</html>

如果发送电子邮件,将显示“已成功提交”消息。三秒钟后,它将重定向到http://mysite.com/contact.php。将http://mysite.com/contact.php更改为您要返回的网址。

答案 1 :(得分:0)

虽然Wayne Whitty的答案是对的,但我确实有另一个注释/答案:

要在3秒后重定向,请使用:

<meta http-equiv="refresh" content="3;url=http://YOURPAGE.php">

我看到你从另一个页面重定向,但这是无用的。你也可以把它放在主页面中,并在提交后使用它只重定向。 (表格是一个例子,我不知道你的表格是怎样的)

<form action="register.php" method="post">
Username <input type="text" name="name">
Password <input type="text" name="email">
Message <input type="text" name="message">
<input name="register" type="submit" value="Register">
</form>


<?php 
if (isset($_POST['name'])) {
echo'<meta http-equiv="refresh" content="3;url=http://YOURPAGE.php">';
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$formcontent = "From: $name \r\n Message: $message";
$recipient = "myemail@email.com";
$mailheader = "From: $email \r\n";
mail($recipient, $message, $formcontent, $mailheader) or die("Error!");
echo "submitted successfully";
}
?>

另外,只需将echo "Thank You!";替换为echo "submitted successfully";