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
DSM
Forum Contributor
Posts: 101 Joined: Thu May 02, 2002 11:51 am
Location: New Mexico, USA
Post
by DSM » Wed Jun 05, 2002 3:55 pm
Working on a mail() function, and I need to be able to grab an array and insert the array items into the body of my email.
I am using a for loop right now, but I only get the last item in the array printed into the email. Any ideas?
Code: Select all
$num_rows = count($item_name);
for($i = 0; $i < $num_rows; ++$i):
$items = "ї$item_nameї$i](*$qtyї$i])]";
endfor;
$headers .= "Content-Type: text/html; charset=iso-8859-1\n";
$headers .= "From: Website<sales@website.com>\n";
$mail = "<html><body>New COD Order<br><br>
For:$full_name<br>
Email:$email<br>
Phone:$phone<br>
Address:$address<br>
City:$city<br>
State:$state<br>
Zip Code:$zip_code<br><br>
Item Name(s)$items<br><br>
Shipping:$shipping<br>
COD:$cod<br>
Total:$total
</body></html>";
$to = "me@website.com";
$subject = "COD order";
mail($to,$subject,$mail,$headers);
twigletmac
Her Royal Site Adminness
Posts: 5371 Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK
Post
by twigletmac » Wed Jun 05, 2002 4:05 pm
It's because each time the for loop iterates you replace $items with new data - so what gets printed out is the last result. You need to concenate the string if you want it to work so:
Code: Select all
$items = '';
for($i = 0; $i < count($item_name); ++$i) {
$items .= "ї$item_nameї$i](*$qtyї$i])]";
}
Hope it helps,
Mac
DSM
Forum Contributor
Posts: 101 Joined: Thu May 02, 2002 11:51 am
Location: New Mexico, USA
Post
by DSM » Wed Jun 05, 2002 4:13 pm
Thx, worked perfect.