Sending thousands of emails from a PHP script is a bit messy at best. One of the real problems is to ensure that the script keeps running as long as necessary to do the job. You can do that if you keep resetting the time out for PHP and you have permission to do that, but there's still going to be a host of other problems.
The best thing to do is to build the email message and the list of recipients in PHP then hand the task of mailing off to something else - either a shell script or some kind of application that gets spawned off and detached from PHP in some way.
Also have you tried using SwiftMailer etc?