我使用以下代码创建 csv 文件并将其发送到 php 中的特定邮箱。我可以成功接收 csv 文件,但是,我不明白为什么还要附加一个名为 ATT00001.txt 的 txt 文件。谁能帮我看看?
以下是发送邮件的部分代码:
// email fields: to, from, subject, and so on
$to = "you@home.com";
$from = "me@home.com";
$subject ="Test mail";
$message = "please check the csv out!";
$headers = "From: $from";
$fileName = pathtocsv;
// boundary
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
// headers for attachment
$headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\"";
// multipart 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";
$message .= "--{$mime_boundary}\n";
// preparing attachments
$file = fopen($fileName,"rb");
$data = fread($file,filesize($fileName));
fclose($file);
$data = chunk_split(base64_encode($data));
$message .= "Content-Type: {\"application/octet-stream\"};\n" . " name=\"record.csv\"\n" .
"Content-Disposition: attachment;\n" . " filename=\"test.csv\"\n" .
"Content-Transfer-Encoding: base64\n\n" . $data . "\n\n";
$message .= "--{$mime_boundary}\n";
mail($to, $subject, $message, $headers);
当我查看它时,它只是一个空的txt文件。我在 Outlook 中打开邮件。