Help! foreach loop in html email

I’ve setup a quote system on a website using php jcart. Found a modified version that emailed form and cart contents into an email.
To make the email look a bit nicer in formatting I decided to try to get it to html format. I can get the form fields that the customer enters to email in a table. Name, Email, Phone, Details etc BUT cannot get the cart contents included in the html email.

I’ve done a lot of reading and so far have had no luck getting anything to work from what information I have found.

Here’s the current code that I have it emails me in a table the information customer enters such as name, phone, email:

[php]
$to = ‘[email protected]’;
$subject = ‘New Online Quote’;
$message = ’

test html online quote

<body>
<table cellspacing=\"4\" cellpadding=\"4\" border=\"1\" align=\"center\">	
	<tr><td><strong>Name:</strong></td><td>' . $_POST['name'] . '</td></tr>
	<tr><td><strong>Email:</strong></td><td>' . $_POST['email'] . '</td></tr>
	<tr><td><strong>Phone:</strong></td><td>' . $_POST['phone'] . '</td></tr>
	<tr><td><strong>Address/Event Details:</strong></td><td>' . $_POST['address'] . '</td></tr>
      </table>
	  <BR><BR>
	  <table border=\"1\">
	  <tr><td>Item Number</td><td>Product</td><td>Price</td><td>Qty</td></tr>
	  </table>
';
// To send HTML mail, the Content-type header must be set

$headers = ‘MIME-Version: 1.0’ . “\r\n”;
$headers .= ‘Content-type: text/html; charset=iso-8859-1’ . “\r\n”;

// Additional headers

$headers .= ‘To: My Name <[email protected]>’ . “\r\n”;
$headers .= ‘From: My Name’ . “\r\n”;

// Mail it
mail($to, $subject, $message, $headers);
[/php]

==========================================

Heres what I’m having trouble with. How do I get the cart contents sent to me in a html email? The following code worked well to email me contents in plain text. I have no idea how to modify it to send me cart as html email

[php]
$i=1;
foreach ($cart->get_contents() as $item)
{
$message .= $i.’ .Item: '. $item[‘name’];
$message .= " Price: " . $item[‘price’];
$message .= " Quantity: " . $item[‘qty’];
$message .= “\n\n”;
$i++;
}
[/php]

try something like this

[php]
$i=1;
foreach ($cart->get_contents() as $item)
{
$itemnum = $i.’ .Item: ';
$namevalue = $item[‘name’];
$pricevalue = $item[‘price’];
$quantityvalue = $item[‘qty’];
$i++;
}

$to = ‘[email protected]’; $subject = ‘New Online Quote’; $message = ’ test html online quote <table cellspacing=“4” cellpadding=“4” border=“1” align=“center”>

Name: ’ . $_POST[‘name’] . ’ Email: ’ . $_POST[‘email’] . ’ Phone: ’ . $_POST[‘phone’] . ’ Address/Event Details: ’ . $_POST[‘address’] . ’

<table border=“1”> Item Number : '.$itemnum.' Product : '.$namevalue.' Price: '.$pricevalue.' Qty '.$quantityvalue.' [/php]

Thanks for your help…Just before I checked this forum again I had come up with an idea like what you had posted except I had all the table data in one row. Except I still was not getting all the contents in the cart.

[php]$i=1;

      foreach ($cart->get_contents() as $item)
         {
         $message .=  $i.' .Item:  '. $item['name'];
         $message .= "   Price: "   . $item['price'];
         $message .= "   Quantity: " . $item['qty'];
         $message .= "\n\n";
       $i++;
         }

$to = ‘[email protected]’;
$subject = ‘New Online Quote’;
$message = ’

test html online quote

<body>
<table cellspacing=\"4\" cellpadding=\"4\" border=\"1\" align=\"center\">	
	<tr><td><strong>Name:</strong></td><td>' . $_POST['name'] . '</td></tr>
	<tr><td><strong>Email:</strong></td><td>' . $_POST['email'] . '</td></tr>
	<tr><td><strong>Phone:</strong></td><td>' . $_POST['phone'] . '</td></tr>
	<tr><td><strong>Address/Event Details:</strong></td><td>' . $_POST['address'] . '</td></tr>
	<tr><td>' .$i .'</td><td>' .$item['name'] . '</td><td>' .$item['price'] . '</td><td>' .$item['qty'] . '</td></tr> </table>
'; [/php]

Looking at how I now had the cart contents appearing in a table I modified my original code and now have it working. Needs some adjustments to table formatting but is now looping through the cart contents and emails them in a table.

[php]$message .= “Message title heading:\n\n”;
$message .= ‘

’;
$message .= ‘’;
 $i=1;
      foreach ($cart->get_contents() as $item)
         {
		 $message .= '<tr>';
		 $message .= '<td>'. $i .' ' .$item['name'] . '</td>';
                     $message .= '<td>' .$item['price'] . '</td>';
		 $message .= '<td>' .$item['qty'] . '</td>';
		 $message .= '</tr>';
                     $message .= "\n\n";
       $i++;
         }
			$message .= '</table>';
            $message .= 'Customer Information';
             $message .= "\n\n";
             $message .='Name : '.$_POST['name'];
              $message .= "\n\n";
              $message .='Email : '.$_POST['email'];
               $message .= "\n\n";
               $message .='Phone : '.$_POST['phone'];
                $message .= "\n\n";
               $message .='Address : '.$_POST['address'];

$to = ‘[email protected]’;
$subject = ‘Message subject’;
$headers = ‘MIME-Version: 1.0’ . “\r\n”;
$headers .= ‘Content-type: text/html; charset=iso-8859-1’ . “\r\n”;

// Additional headers
$headers .= ‘To: My Email <[email protected]>’ . “\r\n”;
$headers .= ‘From: My email’ . “\r\n”;

// Mail it
mail($to, $subject, $message, $headers);
[/php]

Item Number Item Price Qty
Sponsor our Newsletter | Privacy Policy | Terms of Service