这是用于发送附有 doc 文件的电子邮件的代码,正在接收电子邮件,但电子邮件中的内容以编码文本格式显示
<?php
$to = $_POST['to'];
$from = $_POST['from'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$fileatt = $_FILES['upload_file']['tmp_name'];
$fileatt_type = $_FILES['upload_file']['type'];//application/msword
$fileatt_name = $_FILES['upload_file']['name'];
$headers = "From: $from";
if (is_uploaded_file($fileatt)) {
$file = fopen($fileatt,'rb');
$data = fread($file,filesize($fileatt));
fclose($file);
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";
$message = "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$message . "\n\n";
$data = chunk_split(base64_encode($data));
$message .= "--{$mime_boundary}\n" .
"Content-Type: {$fileatt_type};\n" .
" name=\"{$fileatt_name}\"\n" .
"Content-Disposition: attachment;\n" .
" filename=\"{$fileatt_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"--{$mime_boundary}--\n";
}
mail($to, $subject, $message, $headers);
?>
我收到的电子邮件是这样的
message:This is a multi-part message in MIME format. --==Multipart_Boundary_x788f8ac40875c8c7a6540be6654be9c8x Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit --==Multipart_Boundary_x788f8ac40875c8c7a6540be6654be9c8x Content-Type: application/msword; name="File_name.doc" Content-Disposition: attachment; filename="File_name.doc" Content-Transfer-Encoding: base64 s pcEAW4AJBAAA+BK/AAAAAAAAEAAAAAAACAAAMhMAAA4AYmpiaqz6rPoAAAAAAAAAAAAAAAAAAAAA AAAJBBYAuEAAAM6QAQDOkAEAFwsAAAAAAAAaAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD//w8AAAAA AAAAAAD//w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SwAAAAAAAIwYAABQAgAAM0sAAEgAAAAqQgAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAADNLAAAAAAAAAAAAAAAAAACLFAAAAAAAACpCAADQAgAAXhcAAAAAAABeFwAAAAAAANwa AAAAAAAAXhcAAAAAAABeFwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAXhcA AAAAAABeFwAAAAAAAF4XAAAAAAAANEUAAAAAAAA0RQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAA== --==Multipart_Boundary_x788f8ac40875c8c7a6540be6654be9c8x--
headers:From: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="==Multipart_Boundary_x788f8ac40875c8c7a6540be6654be9c8x"
所以任何人都可以帮助我一个完美的代码提前谢谢你