1

我正在使用 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;
}
4

1 回答 1

2

改变

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

$header .= "Content-type:text/html; charset=iso-8859-1\r\n";
于 2013-03-29T16:48:01.260 回答