2013-02-08 38 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