如何将列表组织为表并发送到电子邮件?

时间:2012-02-13 08:20:11

标签: php

如何编辑此代码,以便每个数据都采用表格格式,在指定列下,例如Sname将在商店名称下,pname将在产品名称下。谢谢

 $list = '';
$pplresult = mysql_query("SELECT * FROM repplac");   
while($row = mysql_fetch_assoc($pplresult)){ 
    $list .= $row['Sname']     .$row['Pname']     .$row['Psize']     .$row['Pcolour']     .$row['Pquantity']     .$row['Price']."\n"; 
}

//Send email
$to = $email; 
$subject = "YOUR ORDER LIST FROM REACHEASY"; 
$headers = "From: donotreply@rapsody.co.uk"; 
$body = "$list"; 
mail($to,$subject,$body,$headers);

非常感谢。

2 个答案:

答案 0 :(得分:1)

答案 1 :(得分:0)

这可能是一个简单的例子。

 $body = "<html><body><table border='1'>
    <tr>
    <th>Shop Name</th>
    <th>Product Name</th>
    <th>Size</th>
    <th>Color Name</th>
    <th>Quantity</th>
    </tr>";
    $pplresult = mysql_query("SELECT * FROM repplac");   
    while($row = mysql_fetch_assoc($pplresult)){ 
        $body .= "<tr>
            <td>" . $row['Sname'] ."</td>
            <td>" . $row['Pname'] ."</td>
            <td>" . $row['Psize'] ."</td>
            <td>" . $row['Pcolour'] ."</td>
            <td>" . $row['Pquantity'] ."</td>
            </tr>";
    }

    $body .="</table></body></html>";


    //Send email
    $to = $email; 
   $subject = "YOUR ORDER LIST FROM REACHEASY"; 
$headers = "From: donotreply@rapsody.co.uk\r\n";  
$headers  .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

mail($to,$subject,$body,$headers);