将php表发送到电子邮件地址

时间:2013-04-01 09:55:46

标签: php email sendmail phpmailer

我有php格式的表格,我从sql数据库中检索,记录以表格格式显示,我想邮寄从数据库中检索的记录

这是我的PHP代码

$productList

$sql =mysql_query("Select * from products where id IN(".implode(",",$where).")")
$productCount=mysql_num_rows($sql);
    if ($productCount > 0)   {
while($row = mysql_fetch_array($sql)){
        $id = $row["id"];
         $product_name = $row["item_name"];
         $price = $row["price"];
$productList .= '<div class="coupon">
<table width="618" height="201" border="0">
<tr><td colspan="2" rowspan="4" align="left" valign="top">Name '.$product_name.'" </td>
<td> Expires&nbsp;'.$expiry.'</td>
<td width="129" bgcolor="#033B90">Price '.$price.'</td>
</tr>
</table></div>';

有没有办法将产品列表结果发送到邮件地址

<?php echo $dynamicList; ?>

2 个答案:

答案 0 :(得分:0)

请参阅mail function

mail('to@example.org', 'Subject', $dynamicList);

答案 1 :(得分:0)

<?php
// multiple recipients
$to  = 'test@example.com' . ', '; // note the comma
$to .= 'wez@example.com';

// subject
$subject = 'Birthday Reminders for August';

// message
$message = 'HTML message';

// To send HTML mail, the Content-type header must be set
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

// Additional headers
$headers .= 'To: Mary <mary@example.com>, Kelly <kelly@example.com>' . "\r\n";
$headers .= 'From: Birthday Reminder <birthday@example.com>' . "\r\n";
$headers .= 'Cc: birthdayarchive@example.com' . "\r\n";
$headers .= 'Bcc: birthdaycheck@example.com' . "\r\n";

// Mail it
mail($to, $subject, $message, $headers);
?>

检查php mail function