-3

I need a simple way to redirect, after a form submits, to a thank you page.

PHP:

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

My HTML, which I do not want changed:

<form action="mail.php" method="POST" autocomplete="on"></br>
    <p>Name:</p><input type="text" name="Name"  size="20"></br>
    <p>Email:</p><input type="text" name="email"  size="20"></br>
    <p>Message:</p>
    <textarea id="styled" type="textarea" name="message" form="input></textarea></br>
    <pre><input type="submit" value="Send"><input type="reset" value="Clear"></pre>
</form>
cela
  • 2,352
  • 3
  • 21
  • 43
Benjamin
  • 657
  • 2
  • 10
  • 31

6 Answers6

2

You can use below code. You can use a simple PHP script to redirect a user from the page they entered to a different web page. use header.

<?php
  //your code goes here -> mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
  header( 'Location: http://www.yoursite.com/new_page.html' ) ;
?>
Techie
  • 44,706
  • 42
  • 157
  • 243
1

You could try header("location: next_page.php"); note that nothing can be printed to the browser before this though.

0

use header

mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
header('Location : path_to_thank_you_page');
exit();
Yogesh Suthar
  • 30,424
  • 18
  • 72
  • 100
0

Add a header towards the end of mail.php to redirect you to the thank you page. Example

header("Location: thankyou.php");
Pratik Bothra
  • 2,642
  • 2
  • 30
  • 44
0

Use header(Location:"yorpage".php);

give relative path to the file.do not add any php statement before header statement.

Howli
  • 12,291
  • 19
  • 47
  • 72
0

You could rename your index.html in index.php. Then include mail.php in index.php. After form submit redirect on index.php

<?php include('mail.php'); ?>

<form action="<?= $_SERVER['PHP_SELF'];?>" method="POST" autocomplete="on"></br>