cody27 Posted July 29, 2008 Share Posted July 29, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/117128-solved-sessions-in-a-email-form/ Share on other sites More sharing options...
JonnoTheDev Posted July 29, 2008 Share Posted July 29, 2008 $body .= $_SESSION['sessionName'].$newline; Quote Link to comment https://forums.phpfreaks.com/topic/117128-solved-sessions-in-a-email-form/#findComment-602438 Share on other sites More sharing options...
cody27 Posted July 30, 2008 Author Share Posted July 30, 2008 I tried that but in the email that is received there is only a blank space where the session variables should be. Why would this be? Quote Link to comment https://forums.phpfreaks.com/topic/117128-solved-sessions-in-a-email-form/#findComment-603401 Share on other sites More sharing options...
JonnoTheDev Posted July 30, 2008 Share Posted July 30, 2008 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']) Quote Link to comment https://forums.phpfreaks.com/topic/117128-solved-sessions-in-a-email-form/#findComment-603475 Share on other sites More sharing options...
unkwntech Posted July 30, 2008 Share Posted July 30, 2008 Add this before you send the email <?php print_r($_SESSION); ?> Also make sure you have session_start(); on your email script. @neil.johnson - don't forget to wrap code in [ code] tags. Quote Link to comment https://forums.phpfreaks.com/topic/117128-solved-sessions-in-a-email-form/#findComment-603501 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.