1. 程式人生 > >php mail傳送csv附件丟失第一行資訊

php mail傳送csv附件丟失第一行資訊

附件程式程式碼:

$uid = md5(time());
$eol = PHP_EOL;
$message = "--" . $uid . $eol;
$message .= "Content-Type: text/html; charset=UTF-8" . $eol;
$message .= "Content-Transfer-Encoding: 8bit" . $eol . $eol;
$message .= "Please check the attach file." . $eol;
$message .= "--" . $uid . $eol;
$message .= "Content-Type: application/octet-stream; name=\"$fname"" . $eol;
$message .= "Content-Transfer-Encoding: base64" . $eol;
$message .= "Content-Disposition: attachment; filename=\"$filename"" . $eol;
$content = chunk_split(base64_encode(mb_convert_encoding(file_get_contents($file),'UTF-8')));
//$message .= $content.$eol ;//這是有問題的程式碼
$message .= $eol.$content ;//正確的程式碼
$message .= "--" . $uid . "--";

檢視丟失內容的郵件內容 show original

--db9a66bd76c51e6da33912af726022b1
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 8bit

Please check the attach file.
--db9a66bd76c51e6da33912af726022b1
Content-Type: application/octet-stream; name="Z8020181010151831"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="Z8020181010151831.csv"

ZSxjb3VudHJ5LHBvc3Rjb2RlLHRlbGVwaG9uZSxza3UscHJpY2UscG9zdGFnZSxxdHksDQo3MjIx
OTE5OSxLaW0sQnVja2J5LDIgTWFybG93IFJvYWQsS2Vzd2ljayxTQSxBdXN0cmFsaWEsNTAzNSw4
ODM3MTIzNjYsU0gtQ0wtMTgzWDUwMC0xNzUtR1IsMTY2LjEsMCwxLCANCjcyMjUwNjU3LEFtYW5k

檢視未丟失的show original

--db9a66bd76c51e6da33912af726022b1
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 8bit

Please check the attach file.
--db9a66bd76c51e6da33912af726022b1
Content-Type: application/octet-stream; name="Z8020181010151831"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="Z8020181010151831.csv"

NTA5LDQyNTgwMDA4OSxTQUxPTi00MTI4LUJLLDM4LjUsMCwxLCANCjcyMjUzMTMxLEVpbWVhcixI //丟了這一行
ZSxjb3VudHJ5LHBvc3Rjb2RlLHRlbGVwaG9uZSxza3UscHJpY2UscG9zdGFnZSxxdHksDQo3MjIx OTE5OSxLaW0sQnVja2J5LDIgTWFybG93IFJvYWQsS2Vzd2ljayxTQSxBdXN0cmFsaWEsNTAzNSw4 ODM3MTIzNjYsU0gtQ0wtMTgzWDUwMC0xNzUtR1IsMTY2LjEsMCwxLCANCjcyMjUwNjU3LEFtYW5k

是不是content第一行都要截掉,那就多加一行空行,讓他截空行就好了,就加了
$message .= $eol.$content ;
果真沒在丟失