将产品列表发送到电子邮件

时间:2015-03-06 01:50:46

标签: php mysql email

我试图发送用户从我的网站订购的产品列表..我能够发送电子邮件,但产品列表只是显示数组..任何帮助将不胜感激。谢谢:)

这是我的用于获取产品列表的SQL:

$data = array();
$sql = mysql_query("select oi.id ,oi.quantity, p.code, p.name from order_items oi left join product p on p.id = oi.product_id where order_id = $orderID ");
 $result = mysql_query($query) or die(mysql_error());  
 while ($row = mysql_fetch_array($result)) {
 $code = ($result['code'] != "") ? $result['code'] : $result['name'];
 $quantity = $result['quantity'];
 $data[] = ''.$code.' - '.$quantity.'';
 //$content2 = implode("<br>", $data); 
 }

电子邮件部分:

   $mail_content .= '<table id="mytable" cellspacing="0" style="">';
   $mail_content .= '<tr >';
   $mail_content .= '<td width="20%">product</td>';
   $mail_content .= '<td width="20%">Unit Type</td>';
   $mail_content .= '<td width="10%">Quantity</td>';
   $mail_content .= '</tr>';

   $mail_content .= '<tr>';
   $mail_content .= "<td>";
   $mail_content .= "$data";
   $mail_content .= "</td>";
   $mail_content .= '<td width="20%">Unit Type</td>';
   $mail_content .= '<td width="10%">Quantity</td>';
   $mail_content .= '</tr>';
   $mail_content .= '</table>';

1 个答案:

答案 0 :(得分:0)

不确定“产品”和“单位类型”的值来自db

变化:

$data[] = ''.$code.' - '.$quantity.'';

$data[] = array('code'=>$code,'quantity'=>$quantity)

然后

$mail_content .= '<table id="mytable" cellspacing="0" style="">';
$mail_content .= '<tr >';
$mail_content .= '<td width="20%">product</td>';
$mail_content .= '<td width="20%">Unit Type</td>';
$mail_content .= '<td width="10%">Quantity</td>';
$mail_content .= '</tr>';

foreach($data as $d){
$mail_content .='<tr><td>'.$d['code'].'</td><td>unit type ?</td><td>'.$d['quantity'].'</td></tr>';
}


$mail_content .= '</table>';