0

I have a form which sends to my email. Once form is complete and submitted it redirects to a email sent conformation page. I want to display the name on this page grabbing it from the field in which they inserted their name.

EMAIL FORM PHP:

<?php 
$your_email ='info@example.com';

session_start();
$errors = '';
$name = '';
$visitor_email = '';
$user_message = '';

if(isset($_POST['submit']))
{

    $name = $_POST['name'];
    $visitor_email = $_POST['email'];
    $user_message = $_POST['message'];
    ///------------Do Validations-------------

}
?>
Lukus
  • 1,121
  • 3
  • 10
  • 10

2 Answers2

0
header('Location: emailsent.php?name=' . $name);

In emailsent.php

echo $_GET['name'];
ncremins
  • 9,140
  • 2
  • 25
  • 24
  • thanks and if i wanted to get email address aswell would i do header('Location: emailsent.php?name=' . $name, email=' . $email); – Lukus Feb 29 '12 at 23:43
  • You can use: `header('Location: emailsent.php?name='.$name.'&email='. $email); – Yoav Kadosh Feb 29 '12 at 23:47
  • yes indeed, also good to remember when using header() php continues to execute the remaining statements after the header() call. So it's a good idea to stick an exit; afterwards unless you specifically don't want to. – ncremins Feb 29 '12 at 23:51
0

May I ask why are you using header('Location: emailsent.php');? instead of using header you can reload the same page and modify it to show a different content if the email was sent.

<?php 
if(isset($_POST['submit']) && empty($errors)) {
    //show a success message and some html code... e.g.:
    echo 'Thank you, '.$_POST['name']; //this is the senders name
}
?>

If you must use headers, here is a solution

Community
  • 1
  • 1
Yoav Kadosh
  • 4,807
  • 4
  • 39
  • 56