JustinSainton
05-07-2008, 09:23 AM
Hello all,
Any help on this would be a huge help. If it makes me look any better, I'm working with someone else's shoddy coding :D
Here's the code
<?
if(isset($_POST['submit'])) {
$to = "sdsd"; // change to your email address
$name = $cart->shipping_info['first_name'] . " " . $cart->shipping_info['last_name'];
$email = $cart->shipping_info['email'];
$address = $cart->shipping_info['address'] . "<br />" . $cart->shipping_info['address2'] . "<br />" . $cart->shipping_info['city'] . ", " . $cart->shipping_info['state'] . " " . $cart->shipping_info['zip'] . "<br />" . $cart->shipping_info['country'] . "<br />";
$phone = $cart->shipping_info['phone'];
foreach($cart->cart_items as $key => $item) {
$img = $item->info['img'];
$iname = $item->info['name'];
$size = $item->info['size'];
$qty = $item->info['qty'];
$price = $item->info['price'];
$subtotal = $item->info['subtotal'];
}
$order = ' <table cellspacing="1" cellpadding="1" class="cart_table" width="100%">
<tr>
<th colspan="3"></th>
<th width="100"></th>
<th width="60"></th>
<th width="60"></th>
<th width="40" style="text-align: center">Qty</th>
<th width="40" style="text-align: center">Price</th>
<th width="60" style="text-align: center">Subtotal</th>
</tr>
<tr>
<td></td>
<td><img src="' . $img . '" /></td>
<td> ' .$iname . '</td>
<td>' . $size . '</td>
<td></td>
<td></td>
<td align="center">' . $qty . '</td>
<td>$ ' .$price . '</td>
<td>$ ' .$subtotal . '</td>
</tr>
<tr>
<th colspan="8" style="text-align: right">Subtotal: </th>
<th>$<span id="cart_subtotal">' . $cart->subtotal . '</span> </th>
</tr>
<tr>
<th colspan="8" style="text-align: right">Total: </th>
<th>$<span id="cart_total"> ' .$cart->get_total() . '</span> </th>
</tr>
</table>';
$d = date('l dS \of F Y h:i:s A');
$sub = "From - Wine Order ";
$headers = "From: $name <$email>\n";
$headers .= "Content-Type: text/html; charset=iso-8859-1\n";
$mes .= "You have received an order from $name - their email address is $email - Here is their information <br /><br />";
$mes .= "Name: $name <br />";
$mes .= "Address:<br /> ".$address."<br />";
$mes .= 'Phone: '.$phone."<br /><br />";
$mes .= 'Order: '.$order."<br /><br />";
$mes .= 'Date & Time: '.$d;
if (empty($name) || empty($email) || empty($address) || empty($phone))
{
echo " <h4>Sorry all fields are required.</h4>";
echo $mes;
}
elseif(!ereg("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) {
print " <h4>Sorry the email address you entered looks like it's invalid.</h4>";
}
else
{
mail($to, $sub, $mes, $headers);
print " <h4><center>Thank you, ".$name.", for joining our mailing list.<br>We will get back to you as soon as possible</center></h4>";
echo $mes;
}
} else {
?>
Basically, it sends shopping cart results to an email. The foreach loop at the top is only returning the last item in the array, not all of them. The same exact for each loop is used on a different section, successfully, so I'm not sure why it's not working up here. It is late, so I may be missing something easy...any thoughts?
Any help on this would be a huge help. If it makes me look any better, I'm working with someone else's shoddy coding :D
Here's the code
<?
if(isset($_POST['submit'])) {
$to = "sdsd"; // change to your email address
$name = $cart->shipping_info['first_name'] . " " . $cart->shipping_info['last_name'];
$email = $cart->shipping_info['email'];
$address = $cart->shipping_info['address'] . "<br />" . $cart->shipping_info['address2'] . "<br />" . $cart->shipping_info['city'] . ", " . $cart->shipping_info['state'] . " " . $cart->shipping_info['zip'] . "<br />" . $cart->shipping_info['country'] . "<br />";
$phone = $cart->shipping_info['phone'];
foreach($cart->cart_items as $key => $item) {
$img = $item->info['img'];
$iname = $item->info['name'];
$size = $item->info['size'];
$qty = $item->info['qty'];
$price = $item->info['price'];
$subtotal = $item->info['subtotal'];
}
$order = ' <table cellspacing="1" cellpadding="1" class="cart_table" width="100%">
<tr>
<th colspan="3"></th>
<th width="100"></th>
<th width="60"></th>
<th width="60"></th>
<th width="40" style="text-align: center">Qty</th>
<th width="40" style="text-align: center">Price</th>
<th width="60" style="text-align: center">Subtotal</th>
</tr>
<tr>
<td></td>
<td><img src="' . $img . '" /></td>
<td> ' .$iname . '</td>
<td>' . $size . '</td>
<td></td>
<td></td>
<td align="center">' . $qty . '</td>
<td>$ ' .$price . '</td>
<td>$ ' .$subtotal . '</td>
</tr>
<tr>
<th colspan="8" style="text-align: right">Subtotal: </th>
<th>$<span id="cart_subtotal">' . $cart->subtotal . '</span> </th>
</tr>
<tr>
<th colspan="8" style="text-align: right">Total: </th>
<th>$<span id="cart_total"> ' .$cart->get_total() . '</span> </th>
</tr>
</table>';
$d = date('l dS \of F Y h:i:s A');
$sub = "From - Wine Order ";
$headers = "From: $name <$email>\n";
$headers .= "Content-Type: text/html; charset=iso-8859-1\n";
$mes .= "You have received an order from $name - their email address is $email - Here is their information <br /><br />";
$mes .= "Name: $name <br />";
$mes .= "Address:<br /> ".$address."<br />";
$mes .= 'Phone: '.$phone."<br /><br />";
$mes .= 'Order: '.$order."<br /><br />";
$mes .= 'Date & Time: '.$d;
if (empty($name) || empty($email) || empty($address) || empty($phone))
{
echo " <h4>Sorry all fields are required.</h4>";
echo $mes;
}
elseif(!ereg("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) {
print " <h4>Sorry the email address you entered looks like it's invalid.</h4>";
}
else
{
mail($to, $sub, $mes, $headers);
print " <h4><center>Thank you, ".$name.", for joining our mailing list.<br>We will get back to you as soon as possible</center></h4>";
echo $mes;
}
} else {
?>
Basically, it sends shopping cart results to an email. The foreach loop at the top is only returning the last item in the array, not all of them. The same exact for each loop is used on a different section, successfully, so I'm not sure why it's not working up here. It is late, so I may be missing something easy...any thoughts?