邮件文件附件邮件问题

时间:2014-08-07 11:47:34

标签: php email-attachments ziparchive

我正在尝试使用phpMailer发送带有zip附件(包含CSV文件)的邮件。

但是当我执行时,我在指定位置和邮件中获取zip文件,但在两者中我都无法提取CSV文件,表示CRC失败,文件已损坏。

有谁能告诉我解决方案?

<?php

$zip = new ZipArchive();
$now = new DateTime();

$info = pathinfo($filename);
$name = $info['filename'];
$ext = $info['extension'];

$time = "download.zip";
$pathto = "images/importcsv/download.zip";
$res = $zip->open($pathto, ZipArchive::CREATE);
if ($res == true) {
    $zip->addFile($filename, substr($filename, strrpos($filename, '/') + 1));
}

$zip->close();

yii::import('application.extensions.smtpmail.PHPMailer');
$mail = new PHPMailer();
$mail->Host = $dmmodel->host;
$mail->Username = $dmmodel->username;
$mail->Password = $dmmodel->password;
$mail->Mailer = 'smtp';
$mail->Port = $dmmodel->port;
$mail->SMTPAuth = true;
$mail->SMTPSecure = ($dmmodel->smtp_enableSSL == 1 ? 'ssl' : ($dmmodel->smtp_enableSSL == 2 ? 'tls' : ''));

$mail->From = $dmmodel->email_from;
$mail->FromName = $dmmodel->name_from;

$mail->Subject = "Cron Export CSV";
$mail->MsgHTML("Cron Export CSV");
$mail->AddAddress($dmmodel->default_TO, "");
$mail->AddAttachment("images/importcsv/download.zip", "download.zip");
if (!$mail->Send()) {
    echo "Mailer Error: " . $mail->ErrorInfo;
}

0 个答案:

没有答案