【发布时间】:2014-10-22 14:59:29
【问题描述】:
我这里有简单的代码,
但无法使其工作。有没有其他办法?
它通过电子邮件而不是表格发送 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);
【问题讨论】:
-
be.gmail.com这个电子邮件地址正确吗?请添加不起作用的内容。错误? -
没有错误没有,我更改了那个邮箱地址原来的邮箱不一样,我收到了一封邮件但是有html代码。
-
或者be.gemail.com是否正确无所谓。它只是一个标题!
-
我在我的服务器上测试了你的脚本,它对我来说很好。我也使用 gmail 地址。你能检查收到的标题(是否设置了内容类型等)?
-
我需要设置特定编码的.php文件吗?
标签: php html html-email