从表单发送消息后,我如何重定向回上一页



hi我如何在php 中发送回上一页

<?php
$to = "email";
$subject = "mailed from";
$txt = $_POST['first-name']." ".$_POST['last-name']." sends message from. persons number is: ".$_POST['phone']." message is: ".$_POST['message'];
$headers = "From: ".$_POST['email'];
mail($to,$subject,$txt,$headers);
?>

尝试使用php头函数。

示例将在PHP 中

header("Location: $_SERVER['HTTP_REFERER']");

其中PHP.net的$_SERVER['HTTP_REFERER']

The address of the page (if any) which referred the user agent to the current page. This is set by the user agent. Not all user agents will set this, and some provide the ability to modify HTTP_REFERER as a feature. In short, it cannot really be trusted.

<?php
$to = "email";
$subject = "mailed from";
$txt = $_POST['first-name']." ".$_POST['last-name']." sends message from. 
persons number is: ".$_POST['phone']." message is: 
".$_POST['message'];
$headers = "From: ".$_POST['email'];
mail($to,$subject,$txt,$headers);
// Redirect after mail 
header("Location: $_SERVER['HTTP_REFERER']");

?>

Use可以将其用于重定向-

header("Location:pagename.php"(;

将pagename.php替换为您的页面。将其放在邮件代码下方,以便在邮件发送后重定向。

最新更新