Php 返回上一页并返回消息
我有一个问题,因为我是PHP新手。我写了一个简单的联系方式,但在发送了一条信息(一切正常)后,我进入了一个空白页。有没有办法返回到Php 返回上一页并返回消息,php,html,Php,Html,我有一个问题,因为我是PHP新手。我写了一个简单的联系方式,但在发送了一条信息(一切正常)后,我进入了一个空白页。有没有办法返回到contact.html页面并显示消息“发送成功” 您可以使用函数重定向 header('Location: contact.php?msg=Mail Sent'); exit; contact.php if(isset($_GET['msg'])){ echo $_GET['msg']; } 在HTML文件中,您不能使用PHP,因此首先将contact
contact.html
页面并显示消息“发送成功”
您可以使用函数重定向
header('Location: contact.php?msg=Mail Sent');
exit;
contact.php
if(isset($_GET['msg'])){
echo $_GET['msg'];
}
在HTML文件中,您不能使用PHP,因此首先将contact.HTML更改为contact.PHP,然后: 试试这个:
if (mail($to, $subject, $message, $headers)) {
header("location:contact.php?msg=sent successfully");
}
In contact.php
if(isset($_GET['msg'])) {
echo $_GET['msg']
}
您无法在html页面中获取查询字符串,因此需要将其转换为php页面
<?php
header('Location: contact.php?msg=sent successfully');
?>
contact.php page
<?php
if($_GET['msg'])
{ ?>
<p>
Message has been sent successfully.
thank you.
</p>
<?php }
?>
contact.php页面
消息已成功发送。
非常感谢。
其他解决方案:
为消息创建一个新页面Thankyou.html并使用此
<?php
header('Location: Thankyou.html');
?>
由于jquery对我来说仍然陌生,我决定采用第二种解决方案:)。简单和运行!谢谢你很高兴能帮助你。请别忘了点击左边的复选标记接受我的答案。
<?php
header('Location: contact.php?msg=sent successfully');
?>
contact.php page
<?php
if($_GET['msg'])
{ ?>
<p>
Message has been sent successfully.
thank you.
</p>
<?php }
?>
<?php
header('Location: Thankyou.html');
?>