0

I'm having an issue passing $_SESSION variables through a multiple page form process using PHP mail. The emails are coming through fine, although they not displaying the variables. My goal is to have users fill out forms on multiple pages, and have the data emailed back to me.

Page 1

<?php
session_start();
?>
                  <form method="post" action="submitpage.php">
              <label>
                <input type="radio" name="vehicle_type" value="car" checked />
                <img class="img-responsive" src="img/vehicle2.png">
              </label>
              <label>
                <input type="radio" name="vehicle_type" value="suv" />
                <img class="img-responsive" src="img/vehicle2.png">
              </label>
              <label>
                <input type="radio" name="vehicle_type" value="van" />
                <img class="img-responsive" src="img/vehicle2.png">
              </label>                                    
              <label>
                <input type="radio" name="vehicle_type" value="truck" />
                <img class="img-responsive" src="img/vehicle2.png">
              </label>     
              <label>
                <input type="radio" name="vehicle_type" value="none" />
                <img class="img-responsive" src="img/vehicle2.png">
              </label>                    
              </form>

Page 2

<?php
session_start();
$_SESSION['vehicle_type'] = $_POST['vehicle_type'];
?>
                  <form method="post" action="emailexample.php" id="submit-form">
              <input type="Email" name="email">
              <input type="submit" name="submit" value="Submit" id="submitbtn">
              </form>

Page 3

<?php
session_start();

$to      = 'myemail@gmail.com';
$subject = 'test ';
$message = "Your Vehicle Type is: " . $_POST['vehicle_type'] ."\r\n";
$headers = 'From: email@example.com' . "\r\n" .


mail($to, $subject, $message, $headers);
?>
Joel D'Arnot
  • 45
  • 1
  • 7
  • 1
    what session variables? page #3 doesn't use $_SESSION at all, just a $_POST variable... – Marc B Oct 24 '16 at 20:36
  • I tried replacing $_POST with $_SESSION and still got a blank result emailed to me. – Joel D'Arnot Oct 24 '16 at 20:54
  • 1
    To debug, output the entire `$_SESSION` at each stage and see where session values stop persisting. – showdev Oct 24 '16 at 21:10
  • I've added print_r($_SESSION); to page 2, and it constantly comes up empty. It seems that the radio selection on page 1 never gets saved to a session variable when it's selected. Oh the frustration :/ – Joel D'Arnot Oct 25 '16 at 15:57

2 Answers2

0

In page 3

use $_SESSION['vehicle_type'] instead of $_POST['vehicle_type']

BugHunter
  • 1,194
  • 2
  • 9
  • 15
0

On page 1 you should put submit button something like this

<input type="submit" name="submit" value="Submit" />

On page 3 you should change

$message = "Your Vehicle Type is: " . $_SESSION['vehicle_type'] ."\r\n";

and you're missing semicolon in $headers variable at the end. It should be

$headers = 'From: email@example.com' . "\r\n";
dkc
  • 28
  • 6