PHP inside an HTML Email

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

larrytech
Forum Commoner
Posts: 35
Joined: Thu Jun 06, 2002 8:27 am

Post by larrytech »

You will also have to take this outside the initial $message string and then continue.
How will I do that?
larrytech
Forum Commoner
Posts: 35
Joined: Thu Jun 06, 2002 8:27 am

Post by larrytech »

With the code below as it stands

Code: Select all

<? 
while($row = mysql_fetch_array($result)) 
         &#123; 
            // Increment the total cost of all items 
            $totalCost += ($row&#1111;"qty"] * $row&#1111;"itemPrice"]); 
         $unitCost = ($row&#1111;"qty"] * $row&#1111;"itemPrice"]); 
$qty = $row&#1111;"qty"]; 
$itemName = $row&#1111;"itemName"]; 
$price = number_format($row&#1111;"itemPrice"], 2, ".", ","); 
$unitc = number_format($unitCost, 2, ".", ","); 
$totalc = number_format($totalCost, 2, ".", ","); 
$itemlist =  "<tr><td width="15%" height="25">
                     <font face="verdana" size="1" color="black"> 
                          $qty 
                   </font> 
                  </td><td width="55%" height="25"> 
                     <font face="verdana" size="1" color="black"> 
                        $itemName 
                     </font> 
                  </td>
                  <td width="20%" height="25"> 
                     <font face="verdana" size="1" color="black"> 
                        £$price 
                     </font> 
                  </td> 
                  <td width="20%" height="25"> 
                     <font face="verdana" size="1" color="black"> 
                        £$unitc 
                     </font> 
                  </td> 

               </tr>"; 

&#125; 







$message = "<table width="100%" cellspacing="0" cellpadding="0" border="0"> 
         <tr> 
            <td width="15%" height="25" bgcolor="#99cc99"> 
               <font face="verdana" size="1" color="#000000"> 
                    <b>Qty</b> 
               </font> 
            </td> 
            <td width="55%" height="25" bgcolor="#99cc99"> 
               <font face="verdana" size="1" color="#000000"> 
                  <b>Product</b> 
               </font> 
            </td> 
            <td width="20%" height="25" bgcolor="#99cc99"> 
               <font face="verdana" size="1" color="#000000"> 
                  <b>Price Each</b> 
               </font> 
            </td> 
            <td width="20%" height="25" bgcolor="#99cc99"> 
               <font face="verdana" size="1" color="#000000"> 
                  <b>Total</b> 
               </font> 
            </td> 

         </tr><tr>$itemlist</tr><tr> 
                  <td width="100%" colspan="3"> 

                  </td> 
                  <td width="30%" colspan="2"> 
                     <font face="verdana" size="2" color="black"> 
                        <b>Total: £$totalc</b> 
                     </font> 
                  </td> 
               </tr> 
            </table>"; 
              
        

mail('info@larrytech.biz', 'Subject', 
    $message, 
    "To: The Receiver <recipient@some.net>\n" . 
    "From: The Sender <sender@some.net>\n" . 
    "MIME-Version: 1.0\n" . 
    "Content-type: text/html; charset=iso-8859-1"); 
?> 
        
        
            </form> 
<a href="sendorder.php">Submit</a> 
         <?php 
   &#125; 
   include("bottom.php"); 
?>
I get an email with the last item in. Is there some way in which the $itemlist enclosed in the while can be made to loop it's output or put it into an array? You have cracked the problem of display (Thanks! :D), so it is just, I hope, a small leap to get the whole lot displayed.

Many thanks,

Larry
User avatar
d1223m
Forum Commoner
Posts: 80
Joined: Mon Mar 31, 2003 5:15 am
Location: UK, West Sussex

Post by d1223m »

you want to keep the old value of $itemlist and append to it instead of overwiting it each time.

you have :

Code: Select all

$itemlist="<html...";
where you should have:

Code: Select all

$itemlist.="<html...";
which, if your confused is the same as:

Code: Select all

$itemlist=$itemlist."<html...";
larrytech
Forum Commoner
Posts: 35
Joined: Thu Jun 06, 2002 8:27 am

Post by larrytech »

Ah I understand. But... which is the old value of $itemlist?
User avatar
d1223m
Forum Commoner
Posts: 80
Joined: Mon Mar 31, 2003 5:15 am
Location: UK, West Sussex

Post by d1223m »

ah, bad wording sorry

you dont actually keep the old version, you just keep adding to the same version. look up the operators in the manual.. they are ..um.. usefull ;)
larrytech
Forum Commoner
Posts: 35
Joined: Thu Jun 06, 2002 8:27 am

Post by larrytech »

I am sorry if I am being stupid, but when I try

Code: Select all

<?php 

   include("headers.php"); 
        
   switch($_GET&#1111;"action"]) 
   &#123; 
      case "add_item": 
      &#123; 
         AddItem($_GET&#1111;"id"], $_GET&#1111;"qty"]); 
         ShowCart(); 
         break; 
      &#125; 
      case "update_item": 
      &#123; 
         UpdateItem($_GET&#1111;"id"], $_GET&#1111;"qty"]); 
         ShowCart(); 
         break; 
      &#125; 
      case "remove_item": 
      &#123; 
         RemoveItem($_GET&#1111;"id"]); 
         ShowCart(); 
         break; 
      &#125; 
      default: 
      &#123; 
         ShowCart(); 
      &#125; 
   &#125; 
    
   function ShowCart() 
   &#123; 
      // Gets each item from the cart table and display them in 
      // a tabulated format, as well as a final total for the cart 
        
      global $dbServer, $dbUser, $dbPass, $dbName; 

      // Get a connection to the database 
      $cxn = @ConnectToDb($dbServer, $dbUser, $dbPass, $dbName); 
        
      $totalCost = 0; 
      $result = mysql_query("select * from cart inner join items on cart.itemId = items.itemId where cart.cookieId = '" . GetCartId() . "' order by items.itemName asc"); 
      ?> 
      <html> 
      <head> 
      <title> Your Shopping Cart </title> 
      <script language="JavaScript"> 
        
         function UpdateQty(item) 
         &#123; 
            itemId = item.name; 
            newQty = item.options&#1111;item.selectedIndex].text; 
              
            document.location.href = 'basket.php?action=update_item&id='+itemId+'&qty='+newQty; 
         &#125; 
        
      </script> 
      </head> 
<? 
include("top.php"); 
?> 
      <h1>Your Basket</h1> 
      <form name="frmCart" method="get"> 

        
<? 
while($row = mysql_fetch_array($result)) 
         &#123; 
            // Increment the total cost of all items 
            $totalCost += ($row&#1111;"qty"] * $row&#1111;"itemPrice"]); 
         $unitCost = ($row&#1111;"qty"] * $row&#1111;"itemPrice"]); 
$qty = $row&#1111;"qty"]; 
$itemName = $row&#1111;"itemName"]; 
$price = number_format($row&#1111;"itemPrice"], 2, ".", ","); 
$unitc = number_format($unitCost, 2, ".", ","); 
$totalc = number_format($totalCost, 2, ".", ","); 
$itemlist. =  "<tr><td width="15%" height="25"> 
                     <font face="verdana" size="1" color="black"> 
                          $qty 
                   </font> 
                  </td><td width="55%" height="25"> 
                     <font face="verdana" size="1" color="black"> 
                        $itemName 
                     </font> 
                  </td> 
                  <td width="20%" height="25"> 
                     <font face="verdana" size="1" color="black"> 
                        £$price 
                     </font> 
                  </td> 
                  <td width="20%" height="25"> 
                     <font face="verdana" size="1" color="black"> 
                        £$unitc 
                     </font> 
                  </td> 

               </tr>"; 

&#125; 







$message = "<table width="100%" cellspacing="0" cellpadding="0" border="0"> 
         <tr> 
            <td width="15%" height="25" bgcolor="#99cc99"> 
               <font face="verdana" size="1" color="#000000"> 
                    <b>Qty</b> 
               </font> 
            </td> 
            <td width="55%" height="25" bgcolor="#99cc99"> 
               <font face="verdana" size="1" color="#000000"> 
                  <b>Product</b> 
               </font> 
            </td> 
            <td width="20%" height="25" bgcolor="#99cc99"> 
               <font face="verdana" size="1" color="#000000"> 
                  <b>Price Each</b> 
               </font> 
            </td> 
            <td width="20%" height="25" bgcolor="#99cc99"> 
               <font face="verdana" size="1" color="#000000"> 
                  <b>Total</b> 
               </font> 
            </td> 

         </tr><tr>$itemlist</tr><tr> 
                  <td width="100%" colspan="3"> 

                  </td> 
                  <td width="30%" colspan="2"> 
                     <font face="verdana" size="2" color="black"> 
                        <b>Total: £$totalc</b> 
                     </font> 
                  </td> 
               </tr> 
            </table>"; 
              
        

mail('info@larrytech.biz', 'Subject', 
    $message, 
    "To: The Receiver <recipient@some.net>\n" . 
    "From: The Sender <sender@some.net>\n" . 
    "MIME-Version: 1.0\n" . 
    "Content-type: text/html; charset=iso-8859-1"); 
?> 
        
        
            </form> 
<a href="sendorder.php">Submit</a> 
         <?php 
   &#125; 
   include("bottom.php"); 
?>
I get a "Parse error: parse error in /home/h/e/herbsandspices/public_html/dev/sendorder.php on line 77" which is

Code: Select all

$itemlist. =  "<tr><td width="15%" height="25">
and I don't think there is a problem with that...
larrytech
Forum Commoner
Posts: 35
Joined: Thu Jun 06, 2002 8:27 am

Post by larrytech »

oops! it was $itemlist .=!!!

Thanks very much to everybody here. I am very pleased and have been able to carry on with the rest of the project.
Many thanks!!!!!
Larry
Post Reply