How to insert php variables into html email message
Posted: Wed Jun 25, 2008 11:12 am
Hi--
I'm really having a hard time with this code. I think I've set this up according to the manual, but the following things are happening:
1. My variables aren't appearing in the message. I just get blanks.
2. I'm getting all these error messages -- or something? -- at the top of the message body (Please see screenshots).
3. The Bcc: being sent is unformatted html -- just a bunch of tags.
Obviously, I'm missing the correct syntax here.
My workflow here is from my index.html page, which is the form the customer submits. The form is sent to process.php which processes the form. On that page, there' s an include to receipt.php -- the code for which is below. This prints the receipt, and sends the customer a receipt email. The variables are all working in all the pages, so I didn't think they needed to be re-assigned. For example, the upper portion of the code, which prints the receipt in the browser, works fine using the same variables.
Here's the full code for receipt.php:
And here are two screenshots of my output. The first is the html formatted email to the customer:

And here's the Bcc: as it's coming through to an email client:

Thanks
I'm really having a hard time with this code. I think I've set this up according to the manual, but the following things are happening:
1. My variables aren't appearing in the message. I just get blanks.
2. I'm getting all these error messages -- or something? -- at the top of the message body (Please see screenshots).
3. The Bcc: being sent is unformatted html -- just a bunch of tags.
Obviously, I'm missing the correct syntax here.
My workflow here is from my index.html page, which is the form the customer submits. The form is sent to process.php which processes the form. On that page, there' s an include to receipt.php -- the code for which is below. This prints the receipt, and sends the customer a receipt email. The variables are all working in all the pages, so I didn't think they needed to be re-assigned. For example, the upper portion of the code, which prints the receipt in the browser, works fine using the same variables.
Here's the full code for receipt.php:
Code: Select all
<html>
<head>
<title>Groundlevel Store Receipt</title>
<meta name="generator" content="BBEdit 6.5.1">
<style type="text/css" media="all"><!--
.dsR7 /*agl rulekind: base;*/ { width: 467px; height: 90px; }
--></style>
</head>
<body>
<h2>Thank you for your order!</h2>
<div align="left">
<hr>
Your transaction has been approved.
<br><br>
A confirmation email for this order has been sent to the email provided.<br>
<br>
<table class="dsR7" width="456" border="0" cellspacing="0" cellpadding="0">
<tr>
<td></td>
<td><b>Name: </b><?php echo $fullname; ?></td>
</tr>
<tr>
<td></td>
<td><b>Email: </b><?php echo $email; ?><br>
<br>
</td>
</tr>
<tr>
<td></td>
<td><b>Product: </b><?php echo $item; ?><br>
<br>
</td>
</tr>
<tr>
<td></td>
<td><b>Total: </b><?php echo '$'; ?><?php echo$total; ?></td>
</tr>
</table>
</div>
<p>
<i><?php echo $quantity; ?> 1 Groundlevel Store order(s) processed <?php echo $orderdate; ?>.</i>
</body>
</html>
<?php
// The next line has the subject of the message. The remaining lines before the ending tag
// are the body of the message.
$message .= '<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<style type="text/css" media="all"><!--
.dsR5 /*agl rulekind: base;*/ { width: 645px; height: 75px; }
.dsR6 /*agl rulekind: base;*/ { width: 645px; height: 158px; }
.emailtext { color: gray; font-size: 10pt; font-family: Verdana, Arial, Helvetica, sans-serif; }
.headertext { color: gray; font-size: 14pt; font-family: Verdana, Arial, Helvetica, sans-serif; font-weight: bold; }
.ds4 /*agl rulekind: base;*/ { font-size: 15px; }
.ds10 /*agl rulekind: base;*/ { font-size: 12px; }
a:link {
text-decoration: none;
color: #3399FF;
}
a:visited {
text-decoration: none;
}
a:hover {
text-decoration: none;
}
a:active {
text-decoration: none;
}
--></style>
</head>
<body>
<p><img class="dsR5" src="https://ssl21.pair.com/grndlvl/commerce/gl/images/GRLogo.gif" alt="" border="0" /></p>
<p class="headertext">Groundlevel Store Order</p>
<table class="dsR6" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><span class="emailtext">Name:</span></td>
<td class="emailtext"><?php echo $fullname; ?></td>
</tr>
<tr>
<td><span class="emailtext">Email Address:</span></td>
<td class="emailtext"><?php echo $email; ?></td>
</tr>
<tr>
<td><span class="emailtext">Date:</span></td>
<td class="emailtext"><?php echo $orderdate; ?></td>
</tr>
<tr>
<td><span class="emailtext">Product:</span></td>
<td class="emailtext"><?php echo $item;?></td>
</tr>
<tr>
<td><span class="emailtext">Total:</span></td>
<td class="emailtext"><?php echo$total; ?></td>
</tr>
</table>
<p class="headertext"><span class="ds4">Thank You for Your Order</span></p>
<p class="headertext"><span class="ds10">You can expect your order to be delivered promptly. You will also receive notifcation of your shipment along with the tracking information from the carrier you selected for delivery, either USPS, UPS or Fedex. If you have any questions about your order, please email us at: <a href="mailto:sales@groundlevel.net">sales@groundlevel.net.</a></span></p><br><br>
</body>
</html>';
$headers = "From: Groundlevel Store <sales@groundlevel.net>\r\n" .
"Bcc: Groundlevel Store <grndlvl@gmail.com>\r\n" .
"MIME-Version: 1.0\r\n" .
"Content-type: text/html; charset=iso-8859-1";
mail($email,"Your Groundlevel Store Order",$message,$headers); // this line is the ending tag
?>
And here's the Bcc: as it's coming through to an email client:

Thanks