Welcome Guest, Not a member yet? Register   Sign In
Timeout and newsletter
#1

[eluser]abmcr[/eluser]
I need to send an email to 1500 user's email with a php function; because the timeout is limites to 30" how to do this?
I think to create a page for send 100 email and recall it while i have send all the email....
This is the best solution? or an bcc send is better?
Thank you
#2

[eluser]TheFuzzy0ne[/eluser]
OK, you should be able to send up to 100 Emails in only a single call to the Email class. So you should only need to call $this->email->send() 3 times.

You can pass over up to 100 Email addresses in one go, by separating them with a space or a comma:
Code:
$email_addresses = "[email protected], [email protected], [email protected]";
$this->email->to($email_addresses);
$this->email->send();

You can then do this:
Code:
$another_100_email_addresses = getAddresses(2); // This is a fake pager function that doesn't actually exist.
$this->email->to($another_100_email_addresses);
$this->email->send();

Oh, and yes, use BCC if you don't want the recipients to be copied in on everyone else's addresses.
And repeat as necessary. I'd recommend you make a function that grabs 100 Email addresses for you, and concatenates them into a comma separated string.

You may also wish to raise the maximum execution time limit.
Code:
ini_set('max_execution_time', $number_of_seconds);

Hope this helps.
#3

[eluser]TheFuzzy0ne[/eluser]
Here's a hypothetical controller, which should send the Emails. Obviously, your database would probably have a different schema, and you wouldn't want to call this function via a URI without some other countermeasures to prevent it being called by just anyone. It hasn't been tested, but in theory it should work or at least help point you in the direction that I would take.
Code:
<?php
class Emailer extends Controller {
    
    function Emailer()
    {
        parent::Constructor();
    }
    
    function _get_100_addresses()
    {
        static $start_id = 0;
        
        $this->db->select('id', 'email_address');
        $this->db->from('users');
        $this->db->where('id >', $start_id);
        $this->db->order_by('id', 'asc');
        $this->db->limit(100);

        $res = $this->db->get();
        
        if ($res->num_rows() > 0)
        {
            $arr = array();
            foreach ($res->result_array() as $row)
            {
                $arr[] = $row['email_address'];
                $start_id = $row['id'];
            }
            return implode(',', $arr);
        }
        return FALSE;
    }
    
    function send_emails()
    {
        $this->load->database();
        $this->load->library('email');

        $this->email->from('[email protected]', 'Your Name');
        $this->email->subject('Email Test');
        $this->email->message('Testing the email class.');    

        while ($addresses = $this->_get_100_addresses())
        {
            $this->email->bcc($addresses);
            $this->email->send();
        }
        
        $this->load->view('done');
    }
}




Theme © iAndrew 2016 - Forum software by © MyBB