-2

我使用这个 php 邮件程序 一切正常,但是当我附加文件时,目标电子邮件中收到损坏的文件。例如,当我发送 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 {

}
4

2 回答 2

1

必须是您的 Header 包含文件错误
,因为这是附件中的基本错误

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

:P

于 2013-02-08T10:32:48.273 回答
1

你的 PHPMailer 有严重错误试试

于 2013-02-08T12:08:12.967 回答