Attaching multiple files to addattachment() php opencart

社会主义新天地 提交于 2019-12-13 07:09:31

问题


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.

For logs if i do print_r($filePaths); it gives me this output

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 )

Here is my code.

$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.


回答1:


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);
    }

}


来源:https://stackoverflow.com/questions/35287265/attaching-multiple-files-to-addattachment-php-opencart

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!