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);
當你說「發送附件」是什麼意思?該文件是否存在於您指向的服務器上? – AlexC 2012-02-24 19:16:43
它確實存在,我可以用它裏面的原始內容打開它。但是當它通過電子郵件發送時,文件的唯一內容是上傳/文件名。 – Intelwalk 2012-02-24 19:31:15