Page 1 of 1
print out an array
Posted: Tue May 23, 2006 10:22 am
by seaten
Hi guys,
What I want to is to send a customer an email containing the product names they bought.
I have the standard email format under control.
Code: Select all
$Array = array();
$Array[] = "$productName";
@mail("$email", 'Product Details',
"<html><body><p>Dear Mr. $first_name $second_name,<br><br><br> Your products are Array[0]</body></html>",
"To: The Receiver <$email>\n" .
"From: **************>\n" .
"MIME-Version: 1.0\n" .
"Content-type: text/html; charset=iso-8859-1");
Oviously I am only displaying the name for at most one product here.
The question is how do I tackle the problem of multiple product names. So what I want to do is to output the contents of the array in the email.
Posted: Tue May 23, 2006 10:28 am
by hawleyjr
You are going to want to loop through your array.
Code: Select all
//One of many ways
$myArray = array('product 1', 'product 2', 'product 3', 'product 4', 'product 5'....);
foreach($myArray as $ak => $tVal ){
echo $tVal . '<br />';
}
Posted: Wed May 24, 2006 10:37 am
by seaten
I know I am new to this.
But if I try the following output of my email will just prints the code out.
Code: Select all
<?
$Array = array();
$Array[] = "motorola";
@mail("************", 'Product Details',
"<html><body><p>Dear Mr. $first_name $second_name,<br><br><br> Your products are foreach($myArray as $ak => $tVal){ echo $tVal . '<br />'; }</body></html>",
"To: The Receiver <*****************>\n" .
"From: **************>\n" .
"MIME-Version: 1.0\n" .
"Content-type: text/html; charset=iso-8859-1");
?>[
Posted: Wed May 24, 2006 12:00 pm
by aerodromoi
seaten wrote:I know I am new to this.
But if I try the following output of my email will just prints the code out.
Code: Select all
<?
$Array = array();
$Array[] = "motorola";
@mail("************", 'Product Details',
"<html><body><p>Dear Mr. $first_name $second_name,<br><br><br> Your products are foreach($myArray as $ak => $tVal){ echo $tVal . '<br />'; }</body></html>",
"To: The Receiver <*****************>\n" .
"From: **************>\n" .
"MIME-Version: 1.0\n" .
"Content-type: text/html; charset=iso-8859-1");
?>[
If you're looking for a simple solution, you might want to use implode.
Code: Select all
<?php
$products_array = array("product01","product02","product03");
$products_string = implode("<br />\n", $products_array);
$email_body = "<html><body><p>Dear Mr. ".$first_name." ".$second_name.",<br /><br /><br />";
$email_body .= "Your products are: <br />".$products_string."</body></html>";
@mail("************", 'Product Details',$email_body,
"To: The Receiver <*****************>\n" .
"From: **************>\n" .
"MIME-Version: 1.0\n" .
"Content-type: text/html; charset=iso-8859-1");
?>
aerodromoi
btw: The code you've posted won't work because you labelled the foreach part as a string.
Posted: Wed May 24, 2006 12:07 pm
by seaten
Thanks for your help !