0
我真的需要你的幫助。請在下面找到我的代碼:發送郵件附件通過PHP PEAR
if (isset($_FILES['file']) and $_FILES['file'] <> '') { // Jika email disertai attachment
$crlf = "\n";
$headers['MIME-Version'] = '1.0';
$headers['Content-Type'] = 'text/html; charset="UTF-8';
$headers['Content-Transfer-Encoding'] = 'base64\r\n';
$headers['Date'] = date('r', $_SERVER['REQUEST_TIME']);
$headers['Message-ID'] = $_SERVER['REQUEST_TIME'] . md5($_SERVER['REQUEST_TIME']) . '@' . $_SERVER['SERVER_NAME'];
$headers['From'] = "[email protected]";
$headers['To'] = $to;
$headers['Subject'] = $subject;
$mime = new Mail_mime(array('eol' => $crlf));
$mime->setHTMLBody($body);
foreach($_FILES['file']['tmp_name'] as $key => $value){
$file_name = $_FILES['file']['name'][$key]; //nama file (tanpa path)
$tmp_name = $_FILES['file']['tmp_name'][$key]; //nama local temp file di server
$file_type = $_FILES['file']['type'][$key]; //tipe filenya (langsung detect MIMEnya)
$fp = fopen($tmp_name, 'r');
$content = fread($fp, filesize($tmp_name));
$content = addslashes($content);
fclose($fp);
$data = chunk_split(base64_encode($content));
//$mime->addAttachment($tmp_name, $file_type);
$mime->addAttachment($data, $file_type);
}
$body = $mime->get();
$headers = $mime->headers($headers);
我很成功發送我的HTML文本郵件。但是,沒有我上傳的附件。我的代碼出現了什麼問題?
謝謝。
我已經與mime- $> addAttachment($ tmp_name的值,$嘗試file_type)並且所有附件都已成功發送。但是,文件名不會顯示爲真正的文件名。例如:php505.tmp。 –