Codeigniter:在循环发送多个电子邮件时,最后一封电子邮件的电子邮件附件未被清除 [英] Codeigniter: Email attachment of last emails not cleared while sending multiple emails in loop

查看:209
本文介绍了Codeigniter:在循环发送多个电子邮件时,最后一封电子邮件的电子邮件附件未被清除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码循环发送多个电子邮件附件,

My code sends multiple emails in loop with attachment,

问题是最后(以前的所有)电子邮件的附件被附加到下一封电子邮件。

Problem is attachments of last(previous all) emails get attached to next email.

ex。假设在每个数据库中有3个电子邮件(1个附件)(a1.pdf,a2.pdf,a3.pdf)
然后
将邮件附件作为

ex. suppose 3 emails in database with 1 attachment in each(a1.pdf, a2.pdf, a3.pdf) then, it sends email with attachment as

电子邮件1:

附件:a1.pdf

电子邮件2:

附件:a1.pdf,a2.pdf

attachment :a1.pdf, a2.pdf

电子邮件3:

附件:a1.pdf,a2.pdf,a3.pdf

attachment :a1.pdf, a2.pdf, a3.pdf

我正在使用codeigniter框架。

我的代码是(这段代码被循环调用)

My code is (this code is called in loop)



. . .

$ this-> email-> subject($ item-> subject);

$this->email->subject($item->subject);

        $this->email->message($message);
        $attachments='';
        if(strlen($item->attachment) > 5)
        {
            $attachments = explode(',', $item->attachment);
            foreach($attachments as $attachment)
            {
                if(strlen($attachment)>5)
                $this->email->attach(FCPATH . 'attachments/' . $attachment);                    
            }                

        }

      $this->email->send();



. . .

推荐答案

您需要使用 $ this-> email-> (); 清除循环中设置的变量。 阅读手册

You need to use $this->email->clear(); to clean out the variables set within the loop. Read the manual.

这篇关于Codeigniter:在循环发送多个电子邮件时,最后一封电子邮件的电子邮件附件未被清除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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