我这里有简单的代码,
但无法使其发挥作用。还有别的办法吗。?
它通过电子邮件而不是表格发送HTML编码。
还有别的办法吗。?
或者我如何创建csv或excel并自动附加电子邮件。?
$to = "beback@gmail.com";
$subject = 'New Employee file';
$message = "<html>
<head>
<title>New Employee</title>
</head>
<body>
<p>Here IS the New Employee List</p>
<table border=1>
<tr>
<th>FirstName</th>
<th>LastName</th>
<th>POSNum</th>
<th>POSPassword</th>
<th>location</th>
</tr>
<tr>";
$table = "send_payroll"; // Enter Your Table Name
$sql = mysql_query("select last_name,
first_name,
pos_num,
pos_password,
store
from $table");
$columns_total = mysql_num_fields($sql);
while ($row = mysql_fetch_array($sql)) {
$message .="<tr>";
for ($i = 0; $i < $columns_total; $i++) {
$message .='<td>'.$row["$i"].'</td>';
}
$message .="</tr>";
}
$message .="</tr>
</table>
</body>
</html> ";
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "'r'n";
$headers .= "Content-type:text/html;charset=UTF-8" . "'r'n";
$headers .= "From: Nirav <be.gmail.com>'r'n";
echo "$message" ; //Display table correctly
mail($to, $subject, $message, $headers);
参考您的评论,即传入邮件的内容类型为text/plain,我认为问题来自您的本地邮件服务器配置。此外,防火墙可能会阻止或覆盖传出的标头。
尝试使用类似PHPMail的类发送电子邮件。为了进行测试,您可以使用gmail中的SMTP服务器。