我試圖使用PHP郵件()函數發送帶附件的電子郵件。郵件得到傳遞,但在Web郵件文件名中顯示爲「untitle」。隨着Outlook的Avast啓發式塊完全阻止電子郵件。PHP郵件()附件文件名顯示爲「untitle」
請指導我解決這個問題。
這裏是我使用
$recieverAdd = '[email protected]';
$subject = 'Attachment';
$attDescription="emailing lessons";
$filename ='example.pdf';
$file = '/home/user/example.pdf';
$file_size = filesize($file);
$handle = fopen($file, "r");
$content = fread($handle, $file_size);
fclose($handle);
$content = chunk_split(base64_encode($content));
$uid = md5(uniqid(time()));
$name = basename($file);
$from_name = $uname;
$from_mail = '[email protected]';
$replyto ='[email protected]';
$header = "From: $from_name";
$header .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$uid}\"";
$message = "<p><b>Hello </b></p>";
$messageBody = "--{$uid}\n" . "Content-Type: text/html; charset=\"iso-8859-1 \"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $message . "\n\n";
$messageBody .= "--{$uid}\n". "Content-Type: application/octet-stream;\n".
"name=\"{$filename1}\"\n".
"Content-Description: {$filename}\n" .
"Content-Disposition: attachment;\n".
"filename=\"{$filename}\"; size={$file_size};\n" .
"Content-Transfer-Encoding: base64\n\n". $content."\n\n". "--{$uid}--\n";
mail($recieverAdd,$subject,$messageBody,$header)
什麼是'$ filename1'做的名字嗎? – Rikesh
這是錯字。實際上它是代碼 – Rohini
中的$ filename,所有這些與神祕的郵件頭語法混淆是不必要的。只需使用更好的郵件類而不是php的內置郵件()函數。我推薦使用[phpMailer](http://code.google.com/a/apache-extras.org/p/phpmailer/)。它使用起來非常容易,而且更不用擔心有問題。 – SDC