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