2014-05-07 82 views
0

我试图在用户单击确认按钮时以HTML表格的形式从我的数据库发送数据。我能够发送和接收电子邮件,但只有表格标题显示在电子邮件中。我已经尝试在PHP中添加到HTML表格来显示数据,但它似乎并没有工作,我不知道我的代码是完全错误还是代码混乱:S如何将数据库数据发送到html电子邮件

<?php 
include("../config/cn.php"); 
include("/usr/share/php/Mail.php"); 
include("/usr/share/php/Mail/mime.php"); 

// Get the purchase order details 
$query = mysql_query("SELECT Jobs.* FROM Jobs WHERE order_ref = '".$_GET['order_ref']."'"); 
$row = mysql_fetch_array ($query); 



// Set the email content 
$text = 'Text version of email'; 
$html = '<html><body>'; 
$html .= '<table border="1" cellspacing="0" cellpadding="0"><tr><th width="200">Order Ref.</th><th width="200">First Name</th><th width="200">Last Name</th><th width="200">Tracking No.</th></tr>'; 

while($row = mysql_fetch_array($sql)) { 

    $html .= '<tr><td>'.$row['order_ref'].'</td>'; 
    $html .= '<td>'. $row['first_name'].'</td>'; 
    $html .= '<td>'.$row['last_name'].'</td>'; 
    $html .= '<td>'.$row['tracking_number'].'</td>'; 
    $html .= '</tr>'; 

'</table></body></html>'; 
} 

//$file = "/mnt/Jobs/Purchase_Orders/".date("Y", strtotime($row['created']))."/".date("F", strtotime($row['created']))."/PO".$row['id'].".pdf"; 
$crlf = "\n"; 



// Set customers email 
$sendAddress = "[email protected]"; 

// Set the from address 
$hdrs = array(
       'From' => '[email protected]', 
       'Subject' => 'Spineless System' 
      ); 

// Create the email 
$mime = new Mail_mime(array('eol' => $crlf)); 

$mime->setTXTBody($text); 
$mime->setHTMLBody($html); 
//$mime->addAttachment($file, 'application/pdf'); 

$body = $mime->get(); 
$hdrs = $mime->headers($hdrs); 

// Send the email 
$mail =& Mail::factory('mail'); 
// Paper company address 
$mail->send($sendAddress, $hdrs, $body); 
// Production email address ([email protected]) 
$mail->send("[email protected]", $hdrs, $body); 

header("location: joblist.php"); 

/* 
// Update the sent status of the order 
mysql_query("UPDATE purchase_orders SET sent = '".date("Y-m-d H:i:s")."' WHERE id = '".$_GET['edit']."'", $link); 


header("Location: ../production/pdf_email.php?jobno=".$_GET['jobno']."&edit=".$_GET['edit']);*/ 


?> 

回答

1

因为您正在使用$sql而不是$query。所以,你行应的

while($row = mysql_fetch_array($query)) { 

代替

while($row = mysql_fetch_array($sql)) { 

也不需要第一mysql_fetch_array语句While循环服用的所有行的照顾。

+0

正确的感谢,我纠正我的代码与您的修正案,我仍然得到相同的结果。 – user3519721

+0

如何从查询中返回mush行。也固定' ' ';''到$ HTML ='';'部分(它可以/不可以是原因的问题)在此刻 –

+0

有3行 – user3519721

相关问题