title: php - Header('Location') with message
body: <p>I have a form that sends a email with an order number I want to transfer the user onto a thank you page and display a message ""Mail Sent Thank you first name we will contact you shortly Your Order Number :" send_email.php this sends the email and transfers the user to the thank you page: First i do some error checking if there are no errors i send the email</p>
  
  <pre><code>&lt;?php
  
  function isInjected($str) {
      $injections = array('(\n+)',
      '(\r+)',
      '(\t+)',
      '(%0A+)',
      '(%0D+)',
      '(%08+)',
      '(%09+)'
      );
      $inject = join('|', $injections);
      $inject = "/$inject/i";
      if(preg_match($inject,$str)) {
          return true;
      }
      else {
          return false;
      }
  }
  
  function test_input($data) {
      $data = trim($data);
      $data = stripslashes($data);
      $data = htmlspecialchars($data);
      return $data;
  }
  $nameErr = $lastNameErr = $emailErr = $ironingErr = $descriptionErr = $RoomErr = NULL;
  $first_name = $last_name = $email = $ironing = $description = $Rooms ="";
  
  if(isset($_POST['submit'])){
      $from = $_POST['email']; // this is the sender's Email address
      $first_name = $_POST['first_name'];
      $last_name = $_POST['last_name'];
      $ironing = $_POST['ironing'];
      $Rooms = $_POST['Rooms'];
      $Hours = $_POST['Hours'];
      $Description = $_POST['description'];
      // If email injection is detected, redirect to the error page.
      if ( isInjected($from) ) {
      header( "Location: $error_page" );
  }
  
      if (empty($_POST["first_name"])) {
              $nameErr = "Name is required";
          } else {
              $name = test_input($_POST["first_name"]);
              // check if name only contains letters and whitespace
          if (!preg_match("/^[a-zA-Z ]*$/",$name)) {
              $nameErr = "Only letters and white space allowed"; 
                  }
              }
          if (empty($_POST["email"])) {
              $emailErr = "Email is required";
                  } else {
                      $email = test_input($_POST["email"]);
                      // check if e-mail address is well-formed
                      if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
                        $emailErr = "Invalid email format"; 
                      }
                   }
          if (empty($_POST["description"])) {
              $descriptionErr = "Description is required";
                    } else {
                      $description = test_input($_POST["description"]);
                    }
          if (empty($_POST["Rooms"])) {
                  $RoomErr = "Room number is Required";
                    } else {
                      $Rooms = test_input($_POST["Rooms"]);
                    }
                    if (empty($_POST["Hours"])) {
                  $HourErr = "Room number is Required";
                    } else {
                      $Hours = test_input($_POST["Rooms"]);
                    }
                    if ($_POST["Hours"] &lt; 3) {
                  $RoomErr = "Mininum number of Hours : 3";
                    } else {
                      $Rooms = test_input($_POST["Rooms"]);
                    }
  
          if (empty($_POST["ironing"])) {
              $ironingErr = "Ironing is Required";
              } else{
                      $ironing = test_input($_POST["ironing"]);
              }
      if (isset( $nameErr) || isset($lastNameErr) || isset($emailErr) ||
       isset($ironingErr) || isset($descriptionErr) || isset($RoomErr) ) {
  
      // You have an error
  } else {
      $today = date("Ymd");
      $rand = strtoupper(substr(uniqid(sha1(time())),0,4));
      $unique = $today . $rand;
      $to = "someemail.com"; // this is your Email address
      $subject = "Order Sumbittion: " . $unique;
      $subject2 = "Copy of your form submission";
      $message = $first_name . " " . $last_name . " wrote the following:" . "\n\n" . $_POST['description']. "\n\n" . "Number of Rooms: ". $_POST['Rooms'] . "\n\n" ."Number of Hours : ".$_POST['Hours'] . "\n\n" ."Ironing: " . $_POST['ironing'];
      $message2 = "Here is a copy of your message " . $first_name . "\n\n" . $_POST['description']. "\n\n" . "Number of Rooms: " . $_POST['Rooms']. "\n\n"  . "Number of Hours : " . $_POST['Hours'] . "\n\n" ."Ironing: ". $_POST['ironing'] ."\n\n"."Your Odred Number = ". $unique . "\n\n". "Thank you for your Order our Team will be in contact with you shortly."."\n\n". "Check Our facebook page at facebook.com/GlossyCleaningService" ;
      $headers = "From:" . $from;
      $headers2 = "From:" . $to;
      mail($to,$subject,$message,$headers);
      mail($from,$subject2,$message2,$headers2);
  
      // sends a copy of the message to the sender
      header("Location:thank_you.php?first_name={$first_name}");
      exit;
  }
  
  }
  
  
  ?&gt;  
  </code></pre>
  
  <p>On my thank_you.php page i have the following php script </p>
  
  <pre><code>&lt;?php 
      include ('send_mail.php');
  if( isset($_GET['first_name']) ) {
  echo "Mail Sent. Thank you " . $_GET['first_name'] . ", we will contact you shortly.";
  }
  ?&gt;
  </code></pre>
  
  <p>The message i get on my webpage is</p>
  
  <p><strong>"Notice: Undefined variable: unique in /storage/ssd1/717/1954717/public_html/thank_you.php on line 126
  Mail Sent. Thank you , we will contact you shortly., Your Order Number:</strong> "</p>
  
  <p>The webpage doesnt print out the first name or the Order Number it seems like it cannot find it. </p>
  
  <p><strong>UPDATE : I changed my code to Kevin Nelson Answer I dont get any error or the message just blank</strong></p>
  
  <p>CHECK THE PROBLEM HERE : <a href="https://tadzik9634.000webhostapp.com/lest-sidebar.php" rel="nofollow noreferrer">mysite</a></p>