2012-02-24 73 views
0

我有一個問題,下面的代碼發送附件,但文件有正確的名稱,但內容只是其中的文件上傳/名稱。爲什麼下面的代碼會這樣做?mail()MIME附件只是說文件中的文件位置

感謝

 $name_of_uploaded_file= basename($_FILES['uploaded_file']['name']); 
     $uploaddir = "uploads/"; 

     move_uploaded_file($_FILES['uploaded_file']['tmp_name'], $uploaddir.$_FILES['uploaded_file']['name']); 
     $separator = md5(time()); 
     $eol = PHP_EOL; 
     $attachment = chunk_split(base64_encode($uploaddir.$name_of_uploaded_file)); 
     $to = '[email protected]'; 
     $subject = 'New Training Request Ticket #' . $ticketid; 
     $message = 'Ticket #' . $ticketid . ' Has Been Submitted'; 
     $headers = "From: ".$to.$eol; 
     $headers .= "MIME-Version: 1.0".$eol; 
     $headers .= "Content-Type: multipart/mixed; boundary=\"".$separator."\""; 
     $body = "--".$separator.$eol; 
     $body .= "Content-Transfer-Encoding: 7bit".$eol.$eol; 
     $body .= "This is a MIME encoded message.".$eol; 
     $body .= "--".$separator.$eol; 
     $body .= "Content-Type: text/html; charset=\"iso-8859-1\"".$eol; 
     $body .= "Content-Transfer-Encoding: 8bit".$eol.$eol; 
     $body .= $message.$eol; 
     $body .= "--".$separator.$eol; 
     $body .= "Content-Type: application/octet-stream; name=\"".$name_of_uploaded_file."\"".$eol; 
     $body .= "Content-Transfer-Encoding: base64".$eol; 
     $body .= "Content-Disposition: attachment".$eol.$eol; 
     $body .= $attachment.$eol; 
     $body .= "--".$separator."--"; 

     mail($to, $subject, $body, $headers); 
+0

當你說「發送附件」是什麼意思?該文件是否存在於您指向的服務器上? – AlexC 2012-02-24 19:16:43

+0

它確實存在,我可以用它裏面的原始內容打開它。但是當它通過電子郵件發送時,文件的唯一內容是上傳/文件名。 – Intelwalk 2012-02-24 19:31:15

回答

1

你是不讀的文件上的$連接...的代碼行的內容,你是chuck_split婷的文件名。這就是爲什麼只有名字被髮送。你需要做一些文件,如fread(),然後chunk_split

+0

fread做到了!謝謝 – Intelwalk 2012-02-24 21:17:44