Forum Moderators: coopster
page1.php
<?php
session_start();
if ($_POST) {
$_SESSION['var1'] = $_POST['var1'];
$_SESSION['var2'] = $_POST['var2'];
}
else {
echo <<<FORM
my form code in here
FORM;
}
?>
<?php
session_start();
if ($_POST) {
$_SESSION['var3'] = $_POST['var3'];
$_SESSION['var4'] = $_POST['var4'];
$to = $_SESSION['var1'];
$sub = $_SESSION['var2'];
$body = $_SESSION['var3'];
$headers = $_SESSION['var4'];
mail($to, $sub, $body, $headers);
/*
In this example you dont need any of the second set of $_SESSION calls, as the $_POST variables are on that page.
You also dont need the $body and $header calls, as these could just be substituted for the actual variables in the mail function.
However it does show that you could then use all $_SESSION variables in a third page.
Have a play and you may want to print_r($_SESSION) to see what variables you have available in the session array on each page.
*/
}
else {
echo <<<MOREFORM
even more form code
MOREFORM;
}
As depending on what your form is used for security may or may not be a problem.
There have been a number of discussions on this forum about securing sessions, so it may well be worth searching through and reading them.