2013-02-08 39 views
-2

我使用this php mailer 每件事情都是O.k.但是當我附加一個文件時,目標電子郵件中的文件受損。例如,當我發送一個PDF文件接收器無法打開它。當通過PHP郵件發送文件將會損壞

,這是我使用PHPMailer的代碼:

$target_path = "upload_files/"; 

$target_path = $target_path . basename($_FILES['attach']['name']); 

if(move_uploaded_file($_FILES['attach']['tmp_name'], $target_path)) { 

} else{ 

} 

//eupload file end 

require_once 'phpmailer/phpmailer.inc.php'; 
$mail    = new PHPMailer(); 
$body = $message; 
$body = eregi_replace("[\]",'',$body); 

$mail->AddReplyTo($email, $fname." ".$lname); 

$mail->FromName = $fname." ".$lname; 
$mail->From = $email;  

$mail->AddAddress("email address", "some one"); 

$mail->Subject = "something"; 

$mail->body = $body; 

$mail->AddAttachment($target_path); // attachment 

if(!$mail->Send()) { 

} else { 

} 
+1

你能展示一些相關的!代碼,現在我們必須猜測出了什麼問題。 – Tarilo

+1

@Tarilo你想要什麼?損壞的文件?如果你想我可以上傳文件收到的已損壞的文件 – Ehsan

回答

1

您的PHPMailer存在嚴重錯誤try it

1

必須是你的頭包括文件的是錯誤的
becouse這是附件

$headers .= "\r\nMIME-Version: 1.0\r\nContent-Type: multipart/mixed; boundary=\"_1_$boundary\""; 

基本錯誤:P

+0

尺寸比原來更多:d – Ehsan

+0

該如何在郵件正文 $消息=」 \t \t --_ 1_ $邊界 的Content-Type:multipart/alternative的;邊界= \ 「_ 2_8 $邊界\」 --_ 2_8 $邊界 的Content-Type:text/plain的;字符集= \ 「ISO-8859-1 \」 內容傳輸編碼:7位 $ MESSAGE_BODY - -_2_ $ boundary-- - _ 1_ $ boundary Content-Type:application/octet-stream; name = \「$ filename \」 Content-Transfer-Encoding:base64 Content-Disposition:attachment $ attachment --_ 1_ $ boundary--「; – Sood