是否可以从表单中保存php值以供进一步使用?

I currently have a form on one page that calculates a value depending on what the user has entered:

// PROCESS USERS CALCULATIONS
    $ElecAQ = trim($_POST['ElecAQ']);
    $Elecday = trim($_POST['Elecday']);
    $Elecmonth = trim($_POST['Elecmonth']);
    $Elecyear = trim($_POST['Elecyear']);
    $Elecstanding_charge = trim($_POST['Elecstanding_charge']);

<input type="text" style="padding-left: 2px" class="text-box-find" name="ElecAQ" placeholder="0000" value="<?php if(isset($_POST['ElecAQ'])) echo $_POST['ElecAQ'];?>">

  <input type="text" class="day" name="Elecday" style="float: left; margin-right: 2px" value="<?php if(isset($_POST['Elecday'])) echo $_POST['Elecday'];?>" placeholder="DAY" />

<input type="text" class="month"  name="Elecmonth" placeholder="MONTH" style="float: left" value="<?php if(isset($_POST['Elecmonth'])) echo $_POST['Elecmonth'];?>">    

<input type="text" class="year" name="Elecyear" placeholder="YEAR" style="float: left" value="<?php if(isset($_POST['Elecyear'])) echo $_POST['Elecyear'];?>">  

<input type="text" style="padding-left: 2px" class="text-box-find" name="Elecstanding_charge" placeholder=".00" value="<?php if(isset($_POST['Elecstanding_charge'])) echo $_POST['Elecstanding_charge'];?> ">

When this form gets submitted, the page refreshes and the user is shown a success message (the amount of money they could save) and another form prompting them to enter their details to request a quote underneath.

My question is: Is it going to be possible for me to save the values somehow that get entered into the first form and then send them in the email when then second form is submitted?

The page gets refreshed when the first form processed, so when the email is sent from the second form all the values from the first form that I have included the recieving email are blank.

I really hope that I have managed to explain this ok, I am hoping somebody can tell me the best way of doing this?


Here is the section of code to send the email once the second form is submitted:

$emailTo = 'email@email.co.uk';
    $subject = 'Savings Calculator -Submitted request from '.$name;
    $sendCopy = trim($_POST['sendCopy']);
    $body = "First Name: $contactName 

Business Name: $businessname 

Email: $email 

Phone: $phone 

Mobile: $mobile 

Best time of day to call: $time

USERS CALCULATIONS: $_SESSION['ElecAQ']";

    $headers = 'From: ' .' <'.$emailTo.'>' . "
" . 'Reply-To: ' . $email;

You need to add session_start(); at top of your both pages.

Assigning values to session variable

$_SESSION['ElecAQ'] = trim($_POST['ElecAQ']);

Access session value

echo $_SESSION["ElecAQ"];

Try Example

<?php
session_start();

$_SESSION['ElecAQ'] = trim($_POST['ElecAQ']);
$_SESSION['$Elecday'] = trim($_POST['Elecday']);
$_SESSION['$Elecmonth'] = trim($_POST['Elecmonth']);
$_SESSION['$Elecyear'] = trim($_POST['Elecyear']);
$_SESSION['$Elecstanding_charge'] = trim($_POST['Elecstanding_charge']);

// access session values call
echo $_SESSION['ElecAQ'];
?>

Email Code

Just changed USERS CALCULATIONS: $_SESSION['ElecAQ']"; into USERS CALCULATIONS: ".$_SESSION['ElecAQ'];

Updated

$emailTo = 'email@email.co.uk';
$subject = 'Savings Calculator -Submitted request from '.$name;
$sendCopy = trim($_POST['sendCopy']);
$body = "First Name: $contactName 

Business Name: $businessname 

Email: $email 

Phone: $phone 

Mobile: $mobile 

Best time of day to call: $time

USERS CALCULATIONS: ".$_SESSION['ElecAQ'];

$headers = 'From: ' .' <'.$emailTo.'>' . "
" . 'Reply-To: ' . $email;

you can use $_SESSION variable to save variables which can be then used to another form.

use session_start(); at the top to start accessing session variables.

assign values to session variable. $_SESSION["favcolor"] = "green";

to access echo $_SESSION["favcolor"];