2010-03-20 66 views
0

我试图通过PHP中生成的结果集发送电子邮件在php中发送电子邮件无法使用HTML标记

这是代码。

<?php 
$txtMsg = '<table><th>Name</th>'; 
$txtMsg = ''; 
    mysql_connect("localhost", "root", "pop") or die(mysql_error()); 
     mysql_select_db("jpd") or die(mysql_error()); 
     $oustanding = mysql_query("select Name from results") or die(mysql_error()); 
     $num=mysql_num_rows($oustanding); 

     while($row1 = mysql_fetch_array($oustanding)) { 
      ?> 
     <tr> 
      <td><h3><?php echo $row1['Name']; ?></h3></td> 

     </tr> 
<?php 
$txtMsg .= "<tr><td>".$row1['Name']."</td></tr>"; 
}  


ini_set ("SMTP", "xy.domain.com"); 
$mail_to= '[email protected]'; 
$mail_from='[email protected]'; 
$mail_sub='OutStanding Results'; 
$mail_mesg=$txtMsg; 

//Check for success/failure of delivery 
if(mail($mail_to,$mail_sub,$mail_mesg,"From: $mail_from")) 
echo "<br><br>Email Successfully Sent!"; 
else 
echo "<br><br>Error Sending Email!"; 
} 

?> 

问题是,我希望结果以表格格式显示。但不是处理html标签,而是打印它们。

如何获取表格格式的电子邮件?

谢谢。

回答

3

您需要将您的电子邮件指定为HTML。试试这个:

$headerFields = array(
    "From: $mail_from", 
    "MIME-Version: 1.0", 
    "Content-Type: text/html;charset=iso-8859-1" 
); 
mail($mail_to, $mail_sub, $mail_mesg, implode("\r\n", $headerFields)) 
1

默认情况下,电子邮件是使用text/plain MIME类型发送的。

如果要格式化电子邮件,您应该使用带有text/plaintext/html部分的多部分MIME电子邮件。

你可以找到http://www.tuxradar.com/practicalphp/15/5/3

为例,用户也可以发送电子邮件是text/html而不是多,但是这也容易与垃圾邮件过滤器高得分。