Jump to content

Recommended Posts

I've got a problem with how to echo session variables into the email form, as I don't know how to do it basically. The values are sessioned (maybe not the right word) fine so don't worry about that its just the whole how to echo the session variable into the email script using the $body .=

 

Posting script

 

<?php session_start();

echo "<FORM action=\"process-form.php\" method=\"POST\">\n"; 

$newline = "\n";
$premium = $_POST['premium'];
$acuprac = $_POST['acuprac'];
$bonusfield = $_POST['bonusfield'];
$bonustourn = $_POST['bonustourn'];
$toroclasstourn = $_POST['toroclasstourn'];
$elixtourn = $_POST['elixtourn']; 
$acupracmulti = 40 * $acuprac;
$bonusfieldmulti = 50 * $bonusfield; 
$bonustournmulti = 55 * $bonustourn; 
$toroclasstournmulti = 60 * $toroclasstourn;
$elixtournmulti = 60 * $elixtourn;
$premiummulti = 70 * $premium;
$total = $acupracmulti + $bonusfieldmulti + $bonustournmulti + $toroclasstournmulti + $elixtournmulti + $premiummulti;
print "ACU Bonus (2000) Practice $ $acupracmulti <br>\n<br> 
Bonus Balls (2000) Field Grade $ $bonusfieldmulti <br>\n<br> 
Bonus Balls (2000) Tournament $ $bonustournmulti  <br>\n<br>
Toroball Classic (2000) Tournament $ $toroclasstournmulti  <br>\n<br> 
Elixir Tournament (2000) $ $elixtournmulti <br>\n<br>
Elixir Premium (2000) $ $premiummulti <br>\n<br>
Total $ $total";
$_SESSION["acupracmulti"] = $acupracmulti;
$_SESSION["bonusfieldmulti"] = $bonusfieldmulti;
$_SESSION["bonustournmulti"] = $bonustournmulti;                  //these are the variables
$_SESSION["toroclasstournmulti"] = $toroclasstournmulti;
$_SESSION["elixtournmulti"] = $elixtournmulti;
$_SESSION["premiummulti"] = $premiummulti;
$_SESSION["total"] = $total;

?>

 

Email script

 

<?php

//use the Mail.php mthod once- this avoids duplicate emails.
require_once "Mail.php";


//The fields required for the email. $from, $body will be fields that get information from a form entered by the user. $to will be your admins email address. $subject could be hard coded or from form completed by a user.
$from = $_POST['Contact_Email'];
$to = "tc_co@hotmail.com";
$subject = "New Order";
$newline = "\n";
$body = "Details entered by user in order form:".$newline;
//$body .= "hashdh".$newline;

$body .= $_REQUEST['Contact_FullName'].$newline;

$body .= $_REQUEST['Contact_Title'].$newline;

$body .= $_POST['Contact_Organization'].$newline;

$body .= $_POST['Contact_StreetAddress'].$newline;

$body .= $_POST['Contact_Address2'].$newline;
$body .= $_POST['Contact_City'].$newline;
$body .= $_POST['Contact_State'].$newline;
$body .= $_POST['Contact_ZipCode'].$newline;
$body .= $_POST['Contact_Country'].$newline;
$body .= $_POST['Contact_WorkPhone'].$newline;
$body .= $_POST['Contact_HomePhone'].$newline;
$body .= $_POST['Contact_FAX'].$newline;
$body .= $_POST['Contact_Email'].$newline;

//$newLine = "\r\n"; //var

//This is the ip address of our onsite SMTP relay. Changing this will break the code!
$host = "10.59.16.2";

//make the header
$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject);

//set the smtp server
$smtp = Mail::factory('smtp',
array ('host' => $host,));

//define the email
$mail = $smtp->send($to, $headers, $body);

//send the email. You could change the message if you wish.
if (PEAR::isError($mail)) {
echo("<p>" . $mail->getMessage() . "</p>");
} else {

ob_start();

echo "Test";

header("Location: success.html");

ob_flush();
}

?>

 

Any help would be appreciated.

Link to comment
https://forums.phpfreaks.com/topic/117128-solved-sessions-in-a-email-form/
Share on other sites

If it is the correct session key name you are using $_SESSION['sessionKeyName'] then the only reason it would be blank is if it has no value. Print it to the screen before email as a test so:

 

print $_SESSION['sessionKeyName'];

exit();

 

Is it being destroyed anywhere?

unset($_SESSION['sessionKeyName'])

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.