尝试使用Phpmailer添加多个附件文件

时间:2013-11-29 10:59:13

标签: php email attachment phpmailer

我的服务器上有两个文件,我想加入我的邮件(由tcpdf然后由phpmailer生成),但它不起作用,pdf是在没有附件文件的情况下发送的。这是我的代码:

 function SENDmail($pdf) { // $pdf is generated by tcpdf
$mails = explode (";", $_REQUEST['YOU']);

$files = explode ('</br>', $_REQUEST['FILES']); //all my files are like 'blabla.png' or 'blabla.pdf' and are separated by </br>

require_once('phpmailer/class.phpmailer.php');
$mailer = new PHPMailer();
$mailer->IsHTML(true); 
$mailer->CharSet = 'UTF-8';
$mailer->AddReplyTo($_REQUEST['MAIL'], 'Reply To');
$mailer->SetFrom($_REQUEST['MAIL'], $_REQUEST['MAIL']);

foreach ($mails as $mail)
{
    $mailer->AddAddress($mail, 'Send To');
}

foreach ($files as $file)
{
    $mailer-> AddAttachment('../extension/server/php/files/'.$file); /*Can I put the path like that?*/

}
$mailer->Subject = 'blabla';
$mailer->AltBody = "To view the message, please use an HTML compatible email viewer";


$newline = nl2br($_REQUEST['CONT']);
$mailer->Body = $newline;

if ($pdf) {$mailer->AddStringAttachment($pdf, 'blabla on '.date('l jS \of F Y').'.pdf');}

$mailer->Send();
}



$attachment = $pdf->Output('blabla on '.date('l jS \of F Y').'.pdf', 'S');
SENDmail($attachment);

由于

0 个答案:

没有答案