Welcome Guest, Not a member yet? Register   Sign In
Duplicate Attachments with Email Class
#1

[eluser]spider pig[/eluser]
I'm sending emails from a queue with an attachment. The email is sent ok, but the first email has one attachment, the second email has 2 copies of the same attachment, the third email has 3 copies of the same attachment etc. Eventually, there is a PHP error because it can't allocate enough memory. Is there a way to reset the email class between each loop so it only sends one attachment per email.

Since the email queue can have different emails with different email attachments or even no attachments, I can't set the attachment once before the loop.

Here is the code:

Code:
function index() {
    $this->load->library('email');

    // Check for emails in queue
    $this->db->order_by('queueID');
    $query = $this->db->get('email_queue', 40, 0);
    if ($query->num_rows() > 0) {
        foreach ($query->result() as $row) {
            unset($this->email);

            // Send Email
            $config['mailtype'] = 'html';
            $this->email->initialize($config);
            $this->email->from('[email protected]');
            $this->email->to($row->queueEmail);
            $this->email->subject($row->queueSubject);
            if ($row->queueAttachment != NULL and file_exists($row->queueAttachment))
                $this->email->attach($row->queueAttachment);
            $this->email->message('This is the message');
            $result = $this->email->send();
            
            // Delete from queue
            $this->db->where('queueID', $row->queueID);
            $result = $this->db->delete('email_queue');
        }
    }
}

Thanks
#2

[eluser]Thorpe Obazee[/eluser]
Code:
$this->email->clear()
#3

[eluser]spider pig[/eluser]
[quote author="bargainph" date="1245137738"]
Code:
$this->email->clear()
[/quote]

I tried it but it still didn't work, then I had a look at the manual and this works:

Code:
$this->email->clear(TRUE);

Thanks BRAAIIINNNSSS!!! for pointing me in the right direction.
#4

[eluser]Unknown[/eluser]
Same here. Didn't notice that during the first glance.




Theme © iAndrew 2016 - Forum software by © MyBB