为什么我的电子邮件打印HTML

时间:2013-03-29 16:47:18

标签: php email

我发送带有PHP的电子邮件的附件。 一切都好。但我想发送一些用户的详细信息。 细节是用HTML而不是消息打印。

$my_file = 'attach.txt';
$my_path = "path/".$file_name;
$my_name = "noreply@mail.com ";
$my_mail = "noreply@mail.com";
$my_replyto = "noreply@mail.net";
$my_subject = "test E-Mail";
$my_message = htmlspecialchars_decode("<html><body><center><table width='400px' height='400px'><th>career</th><tr><td>Name</td><td>My name</td></tr><tr><td>Email</td><td>My Email</td></tr><tr><td>Post</td><td>My Post</td></tr><tr><td>Address</td><td>My Address</td></tr></table> </center><br><br></body></html>");

$mailto = "myemail@gmail.com";
$content = chunk_split(base64_encode(file_get_contents($my_path)));
$uid = md5(uniqid(time()));
$name = basename($my_path);
$header = "From: ".$my_mail."\r\n";
$header .= "Reply-To: ".$my_replyto."\r\n";
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n";
$header .= "This is a multi-part message in MIME format.\r\n";
$header .= "--".$uid."\r\n";
$header .= "Content-type:text/plain; charset=iso-8859-1\r\n";
$header .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
$header .= $my_message."\r\n\r\n";
$header .= "--".$uid."\r\n";
$header .= "Content-Type: application/octet-stream; name=\"".$my_file."\"\r\n"; 
// use different content types here
$header .= "Content-Transfer-Encoding: base64\r\n";
$header .= "Content-Disposition: attachment; filename=\"".$my_file."\"\r\n\r\n";
$header .= $content."\r\n\r\n";
$header .= "--".$uid."--";

if (mail($mailto, $my_subject, '', $header)) {
echo "email send";
exit;
} else {
echo "Error during mail send.!";
exit;
}

1 个答案:

答案 0 :(得分:2)

变化

$header .= "Content-type:text/plain; charset=iso-8859-1\r\n";

$header .= "Content-type:text/html; charset=iso-8859-1\r\n";