Welcome Guest, Not a member yet? Register   Sign In
how do you do a newsletter (batches)
#1

[eluser]tomdelonge[/eluser]
I don't want to use something like mailchimp. I want to make something myself. Say you have 100 subscriptions. Can you think of a way maybe to have each page visit do 5 or something? Until the list is empty? I don't know if it would be slow or not to check the database every page view to see if any subscriptions are pending.

Any ideas?
#2

[eluser]richthegeek[/eluser]
A simple SQL (MySQL 5+, due to subquery) statement splits the list into groups of 5:
Code:
SELECT GROUP_CONCAT(email,',') AS recipients FROM emails GROUP BY MOD(id,(SELECT ROUND(COUNT(*) / 6) FROM emails));

You can add a WHERE statement between the FROM and GROUP, or a HAVING afterwards (remembering to add the appropriate column in the fieldlist) to limit by unsent.

Hope that helps.
#3

[eluser]tomdelonge[/eluser]
Do you guys think this is a smart way to accomplish this?
@richthegeek that looks good, thanks.
#4

[eluser]sophistry[/eluser]
i suggest using

$this->db->limit(5);

and (if you have enough of them visiting your site) tell the robots to do your work:

Code:
$this->load->library('user_agent');
if ($this->agent->is_robot()) run_subscriptions();
#5

[eluser]renownedmedia[/eluser]
You're all crazy, use cron!
#6

[eluser]n0xie[/eluser]
indeed use cron:

Code:
function sendqueue()
{
$where = "blnSend='0' AND datPlanned <= '".date('Y-m-d')."'";
$this->db->where($where,'',FALSE);
$this->db->limit(5);
$list = $this->db->get('tblemail')->result();

        foreach ($list as $email)
        {
            $this->email->clear();

            $this->email->to($email->to);
            $this->email->from($email->from);
            $this->email->subject($email->subject);
            $this->email->message($email->message);
            
            if($this->email->send())
            {
                $this->db->set('blnSend',1);
                $this->db->set('datSend',date('Y-m-d'));
                $this->db->where('ID_Email', $email->ID_Email);
                $this->db->update('tblemail');
            }
            else
            {
                $this->db->set('blnSend',0);
                $this->db->set('blnError',1);
                $this->db->set('msgError',$this->email->print_debugger());
                $this->db->where('ID_Email', $email->ID_Email);
                $this->db->update('tblemail');
            }
        }
    }
}
#7

[eluser]sophistry[/eluser]
[quote author="Thomas Hunter" date="1254771604"]You're all crazy, use cron![/quote]

ha ha ha! that's the best compliment i can get from someone. all crazy!

cron it is. or maybe robots... really i prefer enlisting robots - it makes me feel superior to them.

.insert big sig here.




Theme © iAndrew 2016 - Forum software by © MyBB