0

hi how can i send back to previous page in 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);


?>
  • 1
    Does this answer your question? [Redirecting to previous page after login? PHP](https://stackoverflow.com/questions/14523468/redirecting-to-previous-page-after-login-php) – Ronak Dhoot Mar 07 '20 at 19:44

2 Answers2

1

Try using php header function.

Example would be in PHP

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

Where $_SERVER['HTTP_REFERER'] by PHP.net is

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']");

?>

kalle
  • 144
  • 1
  • 9
  • header didnt work, this worked but hmm... how to add message to it that message is sent –  Mar 07 '20 at 20:05
0

Use can use this for redirections -

header("Location: pagename.php");

Replace pagename.php with your page. Place it below mailing code so that it will redirect after the mail gets sent.

  • header didnt work, this worked but hmm... how to add message to it that message is sent –  Mar 07 '20 at 20:06