将多个文件附加到addattachment()PHP OpenCart [英] Attaching multiple files to addattachment() php opencart

查看:497
本文介绍了将多个文件附加到addattachment()PHP OpenCart的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在一封电子邮件中发送多个附件.我从下载目录获取文件路径并将其存储在数组中,然后在每个循环中将其附加到mail-> addattachment($ filepath),但它始终选择最后一个附件.我没有添加foreach代码来获取文件名来自数据库.

I want to send multiple attachments in a single email. I get file paths from my download directory and store them in an array and than using for each loop attach them to mail->addattachment($filepath), but it always selects the last attachment.I havent added my foreach code for getting file names from DB.

对于日志,如果我执行print_r($ filePaths);它给了我这个输出

Array ( [0] => /home/ifixandm/public_html/finalUpGrade/download/resumes/03-02-2016_amir_ETicket-EmmiratsView.pdf ) 
Array ( [0] => /home/ifixandm/public_html/finalUpGrade/download/resumes/04-02-2016_Florida-Mall_Ammar-ul-hassan.pdf )

这是我的代码.

$oresumeCtr = 0;
$filePaths = array();
$filePaths[$oresumeCtr] = DIR_DOWNLOAD ."/resumes/" . $upload_resume; // upload resume is name of resume 
foreach($filePaths as $filePath) {

   if (isset($filePath) && file_exists($filePath)) 
    {
    $mail->addAttachment($filePath);
    $this->log->write('resume path in side loop  ' .$filePath);
    }
}
$mail->send();

我想将这些文件作为附件发送到一封电子邮件中.

I want to send these files as attachments in a single email.

推荐答案

尝试类似的方法,我假设所有文件均为pdf格式.

Try something like this, I am assuming all you files are in pdf format.

foreach (glob(DIR_DOWNLOAD ."/resumes/*.pdf") as $filePath) {
    // do something with $filePath

    if (isset($filePath) && file_exists($filePath))
    {
        $mail->addAttachment($filePath);
        $this->log->write('resume path in side loop  ' .$filePath);
    }

}

这篇关于将多个文件附加到addattachment()PHP OpenCart的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆