M
malnak author
PHP runner 6.0- I wanted to share the code I have for sending a html formatted email. This works and is sending a nice email. I have a inserted query values into a HTML document as a template as well as included HTML code in a variable so a couple of tricks in here worth understanding. <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=question&id=19506&image=1&table=forumtopics' class='bbc_emoticon' alt=':)' />
Some of the queries are calculated fields as well. Good luck. Here is the code I have included in a php snippett
// Put your code here.
//$eid = @$_REQUEST["editid1"];
$eid=$_SESSION["Totals_masterkey1"];
echo $eid;
$str = "SELECT orders.OrderName,`order details`.Quantity,products.UnitPrice,products.Weight*`order details`.Quantity AS WeightTot,products.UnitPrice*`order details`.Quantity AS NetTot, products.Weight, products.ProductName, orders.OrderID, orders.CustCode FROM orders INNER JOIN `order details` ON orders.OrderID = `order details`.OrderID INNER JOIN products ON `order details`.ProductID = products.ProductID Where orders.OrderID=$eid";
$result = CustomQuery($str);
$msg = "<table BORDER=1>";
$msg .= "<tr><th><b>OrderName</b></th><th><b>Product Name</th><th><b>Quantity</th><th><b>Unit Weight</th><th><b>Unit Price</th><th><b>Net Weight</th><th><b>Net Cost</th></tr>";
//echo $msg;
while($row = db_fetch_array($result))
{
$msg .= "<tr><td>";
$msg .= $row['OrderName'];
$msg .= "</td><td>" ;
$msg .= $row['ProductName'] ;
$msg .="</td><td>";
$msg .= $row['Quantity'];
$msg .="</td><td>";
$msg .= $row['Weight'];
$msg .="</td><td>" ;
$msg .=$row['UnitPrice'];
$msg .="</td><td>";
$msg .=$row['WeightTot'];
$msg .="</td><td>";
$msg .=$row['NetTot'];
$msg .="</td></tr>";
}
$msg .="</table>";
$result3 = CustomQuery("SELECT venue.VName AS Venue, venue.ShipAddress AS VenueAddress, venue.ShipCity AS VenueCity, venue.ShipState AS VenueState, venue.ShipZip AS VenueZip, customers.CompanyName AS CompanyName FROM venue INNER JOIN orders ON orders.Venue = venue.ID INNER JOIN customers ON customers.CustomerID = orders.CustomerID Where orders.OrderID=$eid"); while($row3 = db_fetch_array($result3))
{
$Venue= $row3['Venue']; $VenueAddress=$row3['VenueAddress'];
$VenueCity=$row3['VenueCity'];
$VenueState=$row3['VenueState'];
$VenueZip=$row3['VenueZip'];
$CompanyName=$row3['CompanyName'];
} //Total Block//
//$str2= "SELECT SUM(products.Weight*`order details`.Quantity) AS WeightTot,SUM(products.UnitPrice*`order details`.Quantity) AS NetTot FROM orders INNER JOIN `order details` ON orders.OrderID = `order details`.OrderID INNER JOIN products ON `order details`.ProductID = products.ProductID WHERE (orders.OrderID=$eid)";
//$result2=customquery($str2);
//while($row = db_fetch_array ($result2))
//{
//$msg .="<tr><td></td><td></td><td></td><td></td><td></td><td>";
//$msg .=$row['WeightTot'];
//$msg .="</td>";
//$msg .="<td>";
//$msg .=$row['NetTot'];
//$msg .="</td></tr>";
//}
//$msg .= "</tbody></table>";
//echo $msg; //load email template
$email_message = file_get_contents("mwp.html");
// replace variables
$email_message = str_replace("##Company_Name##",$CompanyName,$email_message);
$email_message = str_replace("##Venue##",$Venue,$email_message);
$email_message = str_replace("##VenueAddress##",$VenueAddress,$email_message);
$email_message = str_replace("##VenueCity##",$VenueCity,$email_message);
$email_message = str_replace("##VenueState##",$VenueState,$email_message);
$email_message = str_replace("##VenueZip##",$VenueZip,$email_message);
$email_message = str_replace("##ProductTable##",$msg,$email_message);
//$email_message = str_replace("##Website_URL##","http://mycoolwebsite.com",$email_message); // send HTML email
runner_mail(array('to' => $_SESSION["emailID"], 'subject' => "Thank you for your order", 'htmlbody' => $email_message, 'charset' => 'UTF-8'));
//echo $email_message; Here is the code content of a HTML file Notice how I include the ProductTable in the HTML document to come out formatted right.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html; charset=windows-1252">
<TITLE></TITLE>
<META NAME="CREATED" CONTENT="20120504;15364886">
<META NAME="CHANGED" CONTENT="20120504;16001059">
<STYLE TYPE="text/css">
<!--
@page { size: 8.5in 11in }
-->
</STYLE>
</HEAD>
<BODY LANG="en-US" DIR="LTR">
<TABLE WIDTH=719 BORDER=4 BORDERCOLOR="#000000" CELLPADDING=5 CELLSPACING=4 RULES=ROWS STYLE="page-break-before: always; page-break-inside: avoid">
<COL WIDTH=101>
<COL WIDTH=467>
<COL WIDTH=97>
<TR VALIGN=TOP>
<TD WIDTH=101></TD>
<TD WIDTH=467 BGCOLOR="#cccccc">
<H1 ALIGN=CENTER STYLE="margin-left: 0.27in">Midwestern Printing</H1>
</TD>
<TD WIDTH=97></TD>
</TR>
<TR>
<TD COLSPAN=3 WIDTH=693 VALIGN=TOP BGCOLOR="#ffffff">
<P STYLE="margin-left: 0.36in"><B>Thank you</B> ##Company_Name##
for ordering from ACME printing. Please take a moment to
review your confirmation for accuracy.
</P>
<DL>
<DD>##Venue##</DD><DD>
##VenueAddress##</DD><DD>
##VenueCity##, ##VenueState##, ##VenueZip##</DD></DL>
<P STYLE="margin-left: 0.36in">
<BR>
</P>
</TD>
</TR>
</TABLE>
<P STYLE="margin-left: 0.36in"><BR><BR>
</P>
<P>##ProductTable##
</P>
<P STYLE="margin-left: 0.36in"><BR><BR>
</P>
<TABLE WIDTH=717 BORDER=4 BORDERCOLOR="#000000" CELLPADDING=5 CELLSPACING=4 STYLE="page-break-inside: avoid">
<COL WIDTH=691>
<TR>
<TD WIDTH=691 VALIGN=TOP>
<P STYLE="margin-left: 0.36in; font-weight: medium"><FONT FACE="Times New Roman, serif">You
can view updates and tracking information at
http://midwesternprint.com.</FONT></P>
<P STYLE="margin-left: 0.36in; font-weight: medium"><FONT FACE="Times New Roman, serif"><FONT SIZE=3>We
appreciate the opportunity to serve you!</FONT></FONT></P>
<P STYLE="margin-left: 0.36in; font-weight: medium"><FONT FACE="Times New Roman, serif"><FONT SIZE=3>-The
team at ACME</FONT></FONT></P>
</TD>
</TR>
</TABLE>
<P STYLE="margin-left: 0.36in"><BR><BR>
</P>
<P STYLE="margin-left: 0.36in"><BR><BR>
</P>
</BODY>
</HTML>
|
|