2016-08-20 37 views
0

我試圖從我的服務器發送郵件與文件附件,我的問題是郵件到達與除附加文件的內容之外的所有內容,我試過pdf,docx,jpeg ....沒有問題我附上什麼格式,生病空白/空文件。在郵件附件中獲取空文件

進出口運行WAMP的sendmail(服務器),這裏是一個PHP腳本:

<?php 

$email = $_GET['page']; 
function mail_attachment($filename, $path, $mailto, $from_mail, $from_name, $replyto, $subject, $message) { 

$file = $path.$filename; 
$file_size = filesize($file); 
$handle = fopen($file, "r"); 
$content = fread($handle, $file_size); 
fclose($handle); 
$content = chunk_split(base64_encode($content)); 
//$attachment = chunk_split(base64_encode(file_get_contents('./payDoc.pdf', FILE_USE_INCLUDE_PATH))); 
$uid = md5(uniqid(time())); 

$header = "From: ".$from_name." <".$from_mail.">\r\n"; 
$header .= "Reply-To: ".$replyto."\r\n"; 
$header .= "MIME-Version: 1.0\r\n"; 
$header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n"; 
$header .= "This is a multi-part message in MIME format.\r\n"; 
$header .= "--".$uid."\r\n"; 
$header .= "Content-type:text/plain; charset=iso-8859-1\r\n"; 
$header .= "Content-Transfer-Encoding: 7bit\r\n\r\n"; 
$header .= $message."\r\n\r\n"; 
$header .= "--".$uid."\r\n"; 
$header .= "Content-Type: application/octet-stream; name=\"".$filename."\"\r\n"; 
$header .= "Content-Transfer-Encoding: base64\r\n"; 
$header .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n"; 
//$header .= $attachment."\r\n\r\n"; 
$header .= "--".$uid."--"; 

// Messages for testing only, nobody will see them unless this script URL is visited manually 
if (mail($mailto, $subject, "", $header)) { 
    echo "Message sent!"; 
} else { 
    echo "ERROR sending message."; 
} 

}

//File attach 
$my_file = "payDoc.pdf"; 
$my_path = $_SERVER['DOCUMENT_ROOT']."/connect_android/include/"; 

//email is FROM 
$my_name = "Android Store"; 
$my_mail = "[email protected]"; 
$my_replyto = "[email protected]"; 

//email is going TO 
$to_email = $email; 

// Subject of email 
$my_subject = "Order details has arrived "; 



$message = "Please fill the file attached, 
some text to add 
goes here"; 

// send email 
mail_attachment($my_file, $my_path, $to_email, $my_mail, $my_name, $my_replyto, $my_subject, $message); 
+0

你是否在你的php代碼中出現任何錯誤?你調試過嗎? ** error_reporting(1); ** –

+0

nope我得到郵件發送郵遞員,郵件傳輸良好,附加文件是唯一的問題,他是空白的。 – 2Stoned

+0

通常,它鏈接到文件的路徑。所以試着看看你的文件路徑是否好。 –

回答

0

5分鐘前從字面上看到了同樣的問題,結果我錯過了將此添加到我的開放表單標記中。

enctype="multipart/form-data"