You should **never** attempt this by requesting a script from a page. It will time out, it's almost guaranteed. You can, however, initiate it from your logged in administrator area.
This is not a lighthearted task when you consider all the possibilities - I wouldn't give up on finding something open source that's already made.
Along the lines of penders' solution, your script will set some values in a database for a cron job that runs every [your time period] or so that
checks if there is a mailer to be sent, and the record id of the last email sent.
select isactive, email_id, lastrecord from cron_email
(or, some logic based on completed date, see below)
Your entire program is nested in an if
if ((isactive==1) and ($email_id > 0)) {
// do it
}
when the end of the list is reached, isactive is set to 0. Your email statement for selecting records could be something like
$lastrecord=($lastrecord>0)?$lastrecord+1:0;
select * from list order by id limit $lastrecord, $mylimit
Where "$mylimit" is the number of emails you send per chunk.
When you're done,
update cron_email set isactive=0,total_sent=$totalsent,completed=now() where email_id=$email_id
Don't do any of this without some sort of logging scheme in place. You need to know what's up when things go sideways (somehow, they always do at some point.)
With a dedicated server you might be OK?
A side note, some dedicated plans (like goDaddy) still run emails through their parent relay and you have to request increases of the limit (the default is 5000 per
day.) It's not that they won't allow you, it's just that you have to ask.