Welcome Guest, Not a member yet? Register   Sign In
How to throttle send() email?
#1

[eluser]bondjp[/eluser]
Here's the problem: I need to send every day emails to members based on some criteria. Each member receives a different email.
The emails will be sent at different times of the day, based on the GMT time the users are.
So US and Canada will receive at GMT-11 but Australia/New Zealand will receive at GMT+13.
I've setup several functions to handle that. Will need a cron job to do it.

My question now is how i can throttle the emails i send?

Here's my code:

Controller Email:

Code:
//Send email to US and Canadian members, set cron at GMT-11
    function sendUs()
    {
        $data = array();
        $country=array('United States','Canada');
        $users=$this->Sendemail->getUsers($country);
        foreach ($users as $row){
            $username=$row->username;
            $user_id=$row->user_id;
            $city=$row->city;
            $country=$row->country;
            $useremail=$row->email;
            $info=$row->info;
            $zip=$row->zipcode;
            $day=date('Y-m-d');
            $range=100;
                    
            if ($country=='United States'){
            $zipcode=$this->zipcode->get_zips_in_range($zip, $range);
            $data['usersavailable']=$this->Sendemail->getUsersAvailable($user_id,$info,$zipcode,$day,$country,$city);
            } else {
                    $zipcode=0;
            $data['usersavailable']=$this->Sendemail->getUsersAvailable($user_id,$info,$zipcode,$day,$country,$city);
            }
            
            $data['sentusername']=$username;
            if($data['usersavailable']){
            //send Email
            $config['protocol'] = 'mail';
            $this->email->initialize($config);
                    
            $this->email->from('[email protected]', 'My Site');
            $this->email->to($useremail);
            $this->email->subject($username.' How are you?');
            //$view=$this->load->view('email/sendDaily',$data,TRUE);
            $this->email->message($this->load->view('email/sendDaily',$data,TRUE));
            $this->email->send();
            }    
            
        }
        
    }
#2

[eluser]Aken[/eluser]
What do you mean by throttle? Outgoing emails are automatically queued and sent one by one by the mail server. Granted one by one goes pretty fast, outgoing requests always go out in the order they were received.
#3

[eluser]bondjp[/eluser]
[quote author="Aken" date="1280556094"]What do you mean by throttle? Outgoing emails are automatically queued and sent one by one by the mail server. Granted one by one goes pretty fast, outgoing requests always go out in the order they were received.[/quote]

Well if you have 1000 to send, you don't want to send them all at once... Wink
#4

[eluser]Jan_1[/eluser]
maybe put all messages in a database table and let a cronjob(ed script) send always 50 as long as their are some in...
#5

[eluser]WanWizard[/eluser]
[quote author="bondjp" date="1280556243"]Well if you have 1000 to send, you don't want to send them all at once... Wink[/quote]
Why not?

Maybe if you share with us the problem you want to solve, we can help better than when you ask for a solution when we don't know what you want to archieve.
#6

[eluser]bondjp[/eluser]
[quote author="WanWizard" date="1280583162"][quote author="bondjp" date="1280556243"]Well if you have 1000 to send, you don't want to send them all at once... Wink[/quote]
Why not?

Maybe if you share with us the problem you want to solve, we can help better than when you ask for a solution when we don't know what you want to archieve.[/quote]

I was under the impression that if i send thousands of emails at the same time i would be considered as a spammer, that's why i wanted to to control how they are sent...
#7

[eluser]WanWizard[/eluser]
I don't think that your ISP is going to label you a spammer if you have a legitimate mailing list. And if they would, it would be based on the volume, and not on the number of messages per second.

Your method sends them out one by one anyway, and as this is done by cron in the background, you can always use sleep() to pause a few seconds before sending the next one out.
#8

[eluser]bondjp[/eluser]
[quote author="WanWizard" date="1280586972"]I don't think that your ISP is going to label you a spammer if you have a legitimate mailing list. And if they would, it would be based on the volume, and not on the number of messages per second.

Your method sends them out one by one anyway, and as this is done by cron in the background, you can always use sleep() to pause a few seconds before sending the next one out.[/quote]

Ok. Will leave the code like it is and hope it goes well.




Theme © iAndrew 2016 - Forum software by © MyBB