CodeIgniter Forums
email attachments - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Development (https://forum.codeigniter.com/forumdisplay.php?fid=6)
+--- Forum: Issues (https://forum.codeigniter.com/forumdisplay.php?fid=19)
+--- Thread: email attachments (/showthread.php?tid=64467)



email attachments - pgee - 02-22-2016

Hi.
Using the emails library to send attachments, I was getting an issue in a loop of sending emails to recipients, the number of attachments increased to each recipient.

It turns out that the $_attachments private array is not cleared unless the $this->email->clear(TRUE) is explicitly called.  I can sort of see the reason for this, but in the $this->email->send method, the $this->email->clear(); is used, so attachments are not cleared after sending.

I would suggest this is the wrong way around ... if you want attachments to persist across emails, then explicitly set that.  Otherwise send the email and assume the _attachments array is going to be cleared for the next iteration.  I liken this to the way queries work, after get() is called the query is lost unless I set query caching on.

You could amend the code to change the clear method code to automatically wipe attachments.

I don't want to change the CI source, so as a work around I am just explicitly calling $this->email->clear(TRUE); after the email is sent.

Regards
Pete


RE: email attachments - skunkbad - 02-22-2016

Probably not going to happen, since it's been that way for years, and changing it now could break a lot of people's websites. What you can do is create an extension, called libraries/MY_Email.php, and change the Email class to better suit your desires. See the documentation for extending libraries.


RE: email attachments - ivantcholakov - 02-22-2016

MY_Email.php


RE: email attachments - skunkbad - 02-23-2016

(02-22-2016, 11:44 PM)ivantcholakov Wrote: MY_Email.php

Oops ... Ya that  Blush