learn about using:
set_time_limit();
sleep();
unsleep();
When performing a mass mailing you need to ensure that
a) you don't kill the smtp server, as it can only handle X number of outgoing mails before choking (this depends largely upon the individual server)
b) Your script doesn't time out before it reaches the end of the list of addresses
Some server environments will have disabled the set_time_limit() function to prevent endless loops tying up the server resources too heavily.
Take a good look at some of the already available freebie scripts to see how they handle large address databases.
One I used extensively before developing my own was from here: http://php.warpedweb.net/