0

我的网站上有一个基本的联系表格,效果很好。提交时,虽然它会打开一个带有“谢谢”的空白页面......我想可能会打开一个样式化的网页,上面写着“提交成功”显示大约 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!";
?>
4

2 回答 2

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为您要返回的 URL。

于 2013-11-08T20:11:03.993 回答
0

虽然韦恩惠蒂的回答是正确的,但我确实有另一个注释/答案:

要在 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";

于 2013-11-08T20:30:35.933 回答