Jump to content

Email w/ Include


dlf1987

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.