如何在opencart中将多个文件附加到电子邮件中

时间:2016-02-08 22:09:03

标签: php email opencart

我正在开发opencart模块。我想从我的下载目录发送多个文件,并通过电子邮件将其作为附件发送。目前我已经完成了一些代码,它不会发送包含多个附件的单个电子邮件,它会发送多封电子邮件或发送一封带有最后文件名的电子邮件。这是代码。

$oresumeCtr = 0;
$filePaths = array();
if (isset($this->request->post['selected']) && $this->validate_resume_eMail()) {
        foreach ($this->request->post['selected'] as $applicant_id) {
        $resume_name = $this->model_catalog_career->getapplicantresume($applicant_id);
        $upload_resume = $resume_name[0]['upload_resume'];
        $filePaths[$oresumeCtr] = DIR_DOWNLOAD ."/resumes/" . $upload_resume;   
        $this->log->write('resume path name' .$filePaths);
        $mail = new Mail();
        $mail->protocol = $this->config->get('config_mail_protocol');
        $mail->hostname = $this->config->get('config_smtp_host');
        $mail->username = $this->config->get('config_smtp_username');
        $mail->password = $this->config->get('config_smtp_password');
        $mail->port = $this->config->get('config_smtp_port');
        $mail->timeout = $this->config->get('config_smtp_timeout');            

        $mail->setTo($this->request->get['emailid']);
        $mail->setFrom($this->config->get('config_email'));
        $mail->setSender('ifixandrepair.com');
        $mail->setSubject("Resume");
        $message = '<p>Please find attached Resume. <br />Thanks. </p><p>';
        $mail->setHtml($message);
        foreach($filePaths as $filePath) {
            if (isset($filePath) && file_exists($filePath)) {
                $mail->addAttachment($filePath);
           $this->log->write('resume path in side loop  ' .$filePath);
            }

            }
        }
                   $mail->send();

        echo "<center>Resume sent to the email address <b>" . $this->request->get['emailid'] ."</b> successfully.</center>";
}

0 个答案:

没有答案