2

I have a problem that I - sort of - fixed, but I'm curious why it happens.

I'm sending multiple (different) e-mails to multiple users. The template of the e-mail is the same, but every e-mail has some unique data (so bcc is not possible).

This is the code:

function send_email() {
    $CI =& get_instance();  

    $CI->email->clear(TRUE);
    $CI->email->from(xx);

    $CI->email->to($email);
        $CI->email->subject('subject');

    // Set the to load email in view, so the template can call this view
    $data['view'] = 'email/'.$type.'-html';

    $CI->email->message($CI->load->view('email/email-template', $data, TRUE));

    $CI->email->send();
}

xx is of course the from e-mail.

I'm calling this function from within a loop, to some e-mails a PDF file is attached.

The problem is that I receive some e-mails twice, and some weird blank e-mails. I fixed this by adding a

sleep(20);

to my code. Does anyone know why this is happening? There is nothing wrong with the loop or the data, I checked this a couple of time and it does work with the sleep function added.

user1393817
  • 294
  • 1
  • 3
  • 12
  • Email server limitations, i guess... Every shared hosting have it... You shouldn't send too many emails/per minute. – sinisake Jan 22 '14 at 16:20
  • please check this SO Question: http://stackoverflow.com/questions/13971582/codeigniter-email-send-being-send-twice – Kumar V Jan 22 '14 at 16:31
  • Thanks, I already checked that out. It's not my problem, I do not trigger the e-mail sending. A cronjob runs every night, that's when too many emails are send. – user1393817 Jan 22 '14 at 16:45

0 Answers0