Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 242
  • Last Modified:

Emailing a page populated with query

I have a page that I use as an order form.  When people checkout from the site, they are sent to that page.  They are then asked to either print the form and fax it in, or email it.  Now for the printing part, I have no problem. I integrated it and it works good, but for the email, it's another story.  I am using a php mailer to send mail from php and when I build my message, I can't put code in it.  I do something like this :

// you can optionaly send the e-mail directly to client
$mail = new XPertMailer(SMTP_CLIENT);

// set from mail address
$mail->from('info@artizangifts.com');

// send the e-mail
$send = $mail->send('juliamartin@videotron.ca', 'Commande', '$message');

Now, I need the $message variable to be filled with the data retrieved from the database for which I have this code...


<table width="750" border="0" cellspacing="1" cellpadding="1">
  <tr>
    <td width="61%"><p class="MsoNormal">ARTIZAN <br />
      309 Chemin Lakeshore
     </p>
      <p class="MsoNormal">Pointe-Claire, Quebec</p>
    <p class="MsoNormal">H9S 4L6 </p></td>
    <td width="39%"><div align="right" class="style1">ORDER</div></td>
  </tr>
</table>
<br />
<br />
<table width="750" border="0" cellspacing="1" cellpadding="1">
  <tr>
    <td width="13%" valign="top" class="style4">Client info  </td>
    <td width="64%" valign="top" class="style4"><span class="style4">
      <?
 
$dbh=mysql_connect ("localhost", "xxx", "xxx") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("nicolas_catalog");  

//request amount of items desired
$query_tot = mysql_query("SELECT SUM(TotPrice)AS total FROM Cart WHERE Login ='$ln'");
$sum_tot = mysql_fetch_array($query_tot);
$total2 = number_format($sum_tot[total],2);

$query = "Select * from Clients where Login = '$ln'";
$result = mysql_query($query);
$row = mysql_fetch_array($result, MYSQL_NUM);
echo "$row[3]<br>A/S $row[4]<br>$row[5]<br>$row[6], $row[7]<br>$row[8]<br>$row[9]"; ?>
    </span></td>
    <td width="23%" valign="top" class="style4">date : <? print date("F jS, Y"); ?><br />
    Please print this form and fax to
    514-426-1956</td>
  </tr>
</table>
<br />
<br />
<table width="750" border="1" cellpadding="1" cellspacing="1" bordercolor="#333333" bgcolor="#FFFFFF">
<tr>
    <td width="68" bordercolor="#ECE9D8" bgcolor="#CCCCCC" class="style4">Quant</td>
    <td width="406" bordercolor="#ECE9D8" bgcolor="#CCCCCC" class="style4">Description</td>
    <td width="162" align="right" bordercolor="#ECE9D8" bgcolor="#CCCCCC" class="style4">Unit Price   </td>
    <td width="126" align="right" bordercolor="#ECE9D8" bgcolor="#CCCCCC" class="style4">Total Price  </td>
  </tr>
  <?
$query2 = "Select * from Cart where Login = '$ln'";
$result2 = mysql_query($query2);
while ($row2 = mysql_fetch_array($result2, MYSQL_NUM)) { ?>
 
  <tr>
    <td height="25" class="style4"><? echo $row2[2]; ?></span></td>
    <td height="25" class="style4"><span class="style5"></span><? echo $row2[3]; ?></td>
    <td height="25" align="right" class="style4"><span class="style5"></span><? echo number_format($row2[4],2); ?></td>
    <td height="25" align="right" class="style4"><span class="style5"></span><? echo number_format($row2[5],2); ?></td>
  </tr>
 
  <? } ?>
 <tr>
    <td height="25" colspan="3" align="right" class="style4">TOTAL</td>
    <td height="25" align="right" class="style4"><? echo $total2; ?></td>
  </tr></table>

//-----------------------------------------------------------------------------------------

Now my question is how on earth to I put all that in my $message variable?  I can't put php code in there!

or is there another way to do it?  The page to be emailed would be like this one
http://www.artizangifts.com/order.php?ln=Julia

Any help will be appreciated!

Julia
0
John Account
Asked:
John Account
  • 3
1 Solution
 
Muhammad WasifCommented:
For this purpose you can use buffering
<?
ob_start();
?>
<table width="750" border="0" cellspacing="1" cellpadding="1">
  <tr>
    <td width="61%"><p class="MsoNormal">ARTIZAN <br />
      309 Chemin Lakeshore
     </p>
      <p class="MsoNormal">Pointe-Claire, Quebec</p>
    <p class="MsoNormal">H9S 4L6 </p></td>
    <td width="39%"><div align="right" class="style1">ORDER</div></td>
  </tr>
</table>
<br />
<br />
<table width="750" border="0" cellspacing="1" cellpadding="1">
  <tr>
    <td width="13%" valign="top" class="style4">Client info  </td>
    <td width="64%" valign="top" class="style4"><span class="style4">
      <?
 
$dbh=mysql_connect ("localhost", "xxx", "xxx") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("nicolas_catalog");  

//request amount of items desired
$query_tot = mysql_query("SELECT SUM(TotPrice)AS total FROM Cart WHERE Login ='$ln'");
$sum_tot = mysql_fetch_array($query_tot);
$total2 = number_format($sum_tot[total],2);

$query = "Select * from Clients where Login = '$ln'";
$result = mysql_query($query);
$row = mysql_fetch_array($result, MYSQL_NUM);
echo "$row[3]<br>A/S $row[4]<br>$row[5]<br>$row[6], $row[7]<br>$row[8]<br>$row[9]"; ?>
    </span></td>
    <td width="23%" valign="top" class="style4">date : <? print date("F jS, Y"); ?><br />
    Please print this form and fax to
    514-426-1956</td>
  </tr>
</table>
<br />
<br />
<table width="750" border="1" cellpadding="1" cellspacing="1" bordercolor="#333333" bgcolor="#FFFFFF">
<tr>
    <td width="68" bordercolor="#ECE9D8" bgcolor="#CCCCCC" class="style4">Quant</td>
    <td width="406" bordercolor="#ECE9D8" bgcolor="#CCCCCC" class="style4">Description</td>
    <td width="162" align="right" bordercolor="#ECE9D8" bgcolor="#CCCCCC" class="style4">Unit Price   </td>
    <td width="126" align="right" bordercolor="#ECE9D8" bgcolor="#CCCCCC" class="style4">Total Price  </td>
  </tr>
  <?
$query2 = "Select * from Cart where Login = '$ln'";
$result2 = mysql_query($query2);
while ($row2 = mysql_fetch_array($result2, MYSQL_NUM)) { ?>
 
  <tr>
    <td height="25" class="style4"><? echo $row2[2]; ?></span></td>
    <td height="25" class="style4"><span class="style5"></span><? echo $row2[3]; ?></td>
    <td height="25" align="right" class="style4"><span class="style5"></span><? echo number_format($row2[4],2); ?></td>
    <td height="25" align="right" class="style4"><span class="style5"></span><? echo number_format($row2[5],2); ?></td>
  </tr>
 
  <? } ?>
 <tr>
    <td height="25" colspan="3" align="right" class="style4">TOTAL</td>
    <td height="25" align="right" class="style4"><? echo $total2; ?></td>
  </tr></table>
<?
$message = ob_get_contents(); //get all the output in $message
ob_end_clean();
?>

Now all the conent generate page is in $message.

For more info visit
www.php.net/ob_get_contents
0
 
John AccountAuthor Commented:
Ok, well we're getting somewhere, except there are two problems with this solution :

1 - it emails me the html code

2 - What was in the cart initially is not sent.  In other words, it sends me an empty form and I need it to be populated with the items a person orders.

0
 
John AccountAuthor Commented:
Ok, figured out number 2 here... so now, just one last problem, how do I send this email so I doesn't print the html code, but rather display the tables properly?
0
 
John AccountAuthor Commented:
all right.  Figured that one out too.  Thanks wasifg
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now