我得到的形式接受一個附件,發送附件,但如果它是一個文檔是空白:PHP郵件附件是空白
$fileatt = $_FILES['file']['tmp_name']; $fileattType = $_FILES['file']['type']; $fileattName = $_FILES['file']['name']; $file = fopen($fileatt,'rb'); $data = fread($file,filesize($fileatt)); fclose($file); $semi_rand = md5(time()); $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; $headers = "from: $email"; $headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\""; $content = "Info about user"; $content = "This is a multi-part message in MIME format.\n\n" . "--{$mime_boundary}\n" . "Content-Type: text/plain; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $content . "\n\n"; $data = chunk_split(base64_encode($data)); $content .= "--{$mime_boundary}\n" . "Content-Type: {$fileattType};\n" . " name=\"{$fileattName}\"\n" . "Content-Disposition: attachment;\n" . " filename=\"{$fileattName}\"\n" . "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n" . "--{$mime_boundary}--\n"; $send = mail("[email protected]", "Form", $content, $headers); if($send) header('Location: success page'); else header('Location: fail page');
電子郵件正確地發送,沒有用正確的名稱,文件附件類型和文件大小。當它打開時它是空的。
我教程從sitepoint:http://articles.sitep ......郵件PHP/5
我測試了它們所提供的文件和同樣的事情發生。任何想法都會很棒。感謝大家!
這不是PHPBB .....不要使用'[代碼]'標籤。 – 2010-01-12 22:15:54
我在離線服務器上嘗試了我的代碼。我保持文件完全一樣我甚至離開了ini_set調用: ini_set(「SMTP」,「smtp.server.com」); ini_set(「smtp_port」,「25」); ini_set(「sendmail_from」,「$ email」); 導致我相信這個問題是PHP所在的Web服務器。有任何想法嗎? – dcp3450 2010-01-13 17:21:10