1
我正在使用PHP郵件功能發送帶有attachchemnet的郵件。我將文檔附加到郵件中,並且我將它郵寄到郵件中。我的問題是,當我嘗試閱讀我的error.If我下載的文檔文件,並打開我不能在文檔中看到附着document.Here文字編碼...
使用PHP郵件()函數附加文件並從下載郵件中讀取該文件時出現問題
$fileatt = '../'.$_POST['path']; // Path to the file
$fileatt_type = "application/octet-sdiveam"; // File Type
$fileatt_name = $_POST['attachfile'];
$email_from = '[email protected]'; // Who the email is from
$email_subject = $_POST['Subject']; // The Subject of the email
$email_txt = $_POST['Subject']; // Message that the email has in it
$email_to = $_POST['To']; // Who the email is to
$headers = "From: ".$email_from;
$file = fopen($fileatt,'rb');
$data = fread($file,filesize($fileatt));
fclose($file);
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";
$email_message .= "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type:text/html; charset=\"iso-8859-1\"\n" .
"Content-divansfer-Encoding: 7bit\n\n" .
$email_message . "\n\n";
$data = chunk_split(base64_encode($data));
$email_message .= "--{$mime_boundary}\n" .
"Content-Type: {$fileatt_type};\n" .
" name=\"{$fileatt_name}\"\n" .
//"Content-Disposition: attachment;\n" .
//" filename=\"{$fileatt_name}\"\n" .
"Content-divansfer-Encoding: base64\n\n" .
$data . "\n\n" .
"--{$mime_boundary}--\n";
$ok = @mail($email_to, $email_subject, $email_message, $headers);
這是正確的方式嗎?爲什麼我不能閱讀文檔?我不知道。請幫助我。請提前致謝。
解決:
問題是拼寫錯誤。
內容divansfer編碼:應該是內容傳輸編碼:
嘗試'echo $ email_message;'查看構建的字符串,並將其添加到問題中。 – aularon 2010-09-07 07:24:25
你應該真的嘗試使用更好的郵件庫之一,而不是重新發明輪子。我的2美分。我個人一直在使用這個:http://www.phpguru.org/downloads/Rmail/Rmail%20for%20PHP/ – janosrusiczki 2010-09-07 07:26:32
@kitsched我用那個。它顯示郵件發送的消息。但一小時後也我沒有得到任何東西(郵件,附件)。 – svk 2010-09-07 08:44:13