Welcome Guest, Not a member yet? Register   Sign In
Mail not received - using CI email library [RESOLVED]
#1

[eluser]JoostV[/eluser]
Hi all,

I sent a mail to 500 recipients, using the CI mail class. $this->email->print_debugger() says the mail was sent succesfully, and I can see the 500 recipients in the debugger's BCC listing.

However, when I checked with several subscribers, I found out they did not receive the mailing. Hope you guys can help me out here. I'd appreciate any input.

I noticed some invalid e-mailaddresses appear in the list (it's an old imported list, all new members e-mailaddresses are validated). Could that cause the problem?

I tried sending a test newsletter to 2000 testaddresses and that worked just fine.

Here's my controller code.
Code:
function sendmailing () {

    // Load dependent models, etc.
    $this->load->model('newsletters');
    $this->load->library('email');

    // Fetch the newsletter data, including subject, body, etc.
    $this->data['mail'] = $this->newsletters->get($id);

    // Fetch the recipient addresses
    $this->data['adresses'] = $this->_getAdresses();

    // Set up the newsletter
    $this->email->mailtype = 'html';
    $this->email->subject(unformat_field($this->data['mail']['subject']));
    $this->email->message($this->load->view('newsletter', $this->data, true));
    $this->email->from($this->config->item('noreply'));
    $this->email->reply_to($this->config->item('noreply'));
    $this->email->to($this->config->item('noreply'));

    // The subscribers are in BCC
    $this->email->bcc($this->data['adresses']);

    // Send e-mail
    if($this->email->send()) { // Mail was sent succesfully
        echo '<h1>Newsletters was sent to ' . count($this->data['adresses']) . ' recipients</h1>';
    }
    else { // Mail was not sent
        echo '<h1>Mail could not be sent</h1>';
    }
    // Print a debug report
    echo '<p>' . $this->email->print_debugger() . '</p>';

    $this->email->clear();
}
#2

[eluser]Jay Logan[/eluser]
I'm having an issue somewhat similar. I suggest trying to use SMTP and/or maybe a foreach to send your mail.
#3

[eluser]NateL[/eluser]
I wouldn't send an e-mail out to 500 people using BCC. You're most likely overloading the server

I've had success with a small app from a site called NotOneBit.com - Simple Mailer. I realize it's all procedural and not based on a framework, but it's free and it works.

it throttles the amount of e-mails it sends out at once so your e-mails don't get hung up.

If someone wrote a script in CodeIgniter that did the same thing, I'd use it!
#4

[eluser]JoostV[/eluser]
Hi guys, appreciate your help. I will surely look into Simple Mailer.

Meantime, I rewrote the code to throttle in BCC batches of 50 each using sendmail, and all mail seems to arrive fine now.

I use set_time_limit() and ignore_user_abort() to avoid any time out problems.

Code:
// Subscribers are stored in $subscribers
// Newsletter data is stored in $this->data['newsletter']

// Load and configure e-mail class
$this->load->library('email');
$config['mailtype'] = 'html';
$config['protocol'] = 'sendmail';
$config['mailpath'] = '/usr/sbin/sendmail';
$this->email->initialize($config);

// Set message
$message = $this->load->view('newsletter', $this->data, true);
$this->email->message($message);
$this->email->subject($this->data['newsletter']['subject']);
$this->email->from($this->config->item('noreply_address'));
$this->email->reply_to($this->config->item('noreply_address'));
$this->email->to($this->config->item('noreply_address'));

// Set recipients
// Only use validate e-mailaddresses as recipients
foreach ($subscribers as $address) {
    if (preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $address)) {
        $recipients[] = $address;
    }
}

// Set recipients
$this->email->bcc_batch_mode = true;
$this->email->bcc_batch_size = 50;
$this->email->bcc($recipients);

//This could take a while, so we'll override time limits for now
set_time_limit(0);
ignore_user_abort(true);

// Send this mailing
$this->email->send();
#5

[eluser]TheFuzzy0ne[/eluser]
If I recall correctly, only up to 100 recipients are supported. I'm not sure if that period, or per field, but hopefully you can figure that out.




Theme © iAndrew 2016 - Forum software by © MyBB