php邮件发送时文件会损坏

时间:2013-02-08 10:20:20

标签: php phpmailer email-attachments

我使用this php mailer 每件事都是O.k.但是当我附加文件时,损坏的文件会在目标电子邮件中收到。例如,当我发送pdf文件时,接收器无法打开它。

这是我使用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 {

}

2 个答案:

答案 0 :(得分:1)

必须是你的标题包含文件有误 因为这是附件中的基本错误

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

:P

答案 1 :(得分:1)

您的PHPMailer存在严重错误try it