dlf1987 Posted September 9, 2008 Share Posted September 9, 2008 I'm trying to send an email, by including the message from an include. The email goes through, but the sessions on the included page don't show up in the email... is there anyway to fix that? email.php <?php //Sessions $_SESSION['first_name'] = $_POST["first_name"]; $_SESSION['last_name'] = $_POST["last_name"]; // EMAIL function get_include_contents($filename) { if (is_file($filename)) { ob_start(); include $filename; $contents = ob_get_contents(); ob_end_clean(); return $contents; } return false; } $header = 'MIME-Version: 1.0' . "\r\n"; $header .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $message = get_include_contents('email/order_receipt.php'); $Name = "XXXXXX.COM"; $email = "[email protected]"; $recipient = $_SESSION['email']; $mail_body = stripslashes($message); $subject = "XXXXXX - Order Receipt"; $header .= "From: ". $Name . " <" . $email . ">\r\n"; mail($recipient, $subject, "$mail_body", $header); ?> order_receipt.php <strong>Billing Address:</strong><br> <?php $_SESSION['first_name']; ?> <?php $_SESSION['last_name']; ?> Yes, i have session_start(); on both pages. Link to comment https://forums.phpfreaks.com/topic/123501-email-w-include/ Share on other sites More sharing options...
BlueSkyIS Posted September 9, 2008 Share Posted September 9, 2008 oops, you already told us you have session_start() on both pages... Link to comment https://forums.phpfreaks.com/topic/123501-email-w-include/#findComment-637829 Share on other sites More sharing options...
The Little Guy Posted September 10, 2008 Share Posted September 10, 2008 you don't need session_start in the include file, just the main file. and second, you need to have the second page in a variable. <?php $mail_body = '<strong>Billing Address:</strong><br> '.$_SESSION['first_name'].' '.$_SESSION['last_name']'; ?> Link to comment https://forums.phpfreaks.com/topic/123501-email-w-include/#findComment-638006 Share on other sites More sharing options...
The Little Guy Posted September 10, 2008 Share Posted September 10, 2008 Actually I would do this: <?php //Sessions $_SESSION['first_name'] = $_POST["first_name"]; $_SESSION['last_name'] = $_POST["last_name"]; // EMAIL function get_include_contents($filename) { if (is_file($filename)) { ob_start(); include $filename; return $contents; }else{ return false; } } $header = 'MIME-Version: 1.0' . "\r\n"; $header .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $message = get_include_contents('email/order_receipt.php'); $Name = "XXXXXX.COM"; $email = "[email protected]"; $recipient = $_SESSION['email']; $mail_body = stripslashes($message); $subject = "XXXXXX - Order Receipt"; $header .= "From: ". $Name . " <" . $email . ">\r\n"; mail($recipient, $subject, $mail_body, $header); ?> email/order_receipt.php <?php $contents = '<strong>Billing Address:</strong><br> '.$_SESSION['first_name'].' '.$_SESSION['last_name']; ?> Link to comment https://forums.phpfreaks.com/topic/123501-email-w-include/#findComment-638007 Share on other sites More sharing options...
dlf1987 Posted September 10, 2008 Author Share Posted September 10, 2008 Thanks guys, but I was hoping there was another way, cause i wanted to be able to edit the email layout in WYSISYG editor and it doesn't display the structure of the page if its in a var :/ Link to comment https://forums.phpfreaks.com/topic/123501-email-w-include/#findComment-638541 Share on other sites More sharing options...
dlf1987 Posted September 10, 2008 Author Share Posted September 10, 2008 Is there no other way around it? Link to comment https://forums.phpfreaks.com/topic/123501-email-w-include/#findComment-638639 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.