PHP Bulk Email?

ctttdbcd

New Member
So I have a table in a database called tblUsers for example, where there is a column called 'email'. Basically I want a script that will do a query loop and send the email to all of them (not all at once so that the To: field only has them in it and can personalise the email with Hi, [Name]).

However, there are about 900 rows and my hosts limit is 400/hr. So I'd want a code that does the first 400, and then later I can press a button and it will send rows 401-800... then a third button 801-1200 etc. Of course a script that does this automatically would be better, but not quite sure if that's possible.

Can anyone help me ?
(By the way, it is solicited, they know they signed up to get emails).

I'm open to all suggestions!

--------
So far I've tried this but it doesn't work:
PHP:
<?php
$server = "localhost";
$dbname = "###";
$dbuser = "###";
$dbpass = "###";
$conn = mysql_connect($server,$dbuser,$dbpass) or die ("PHP/MYSQL ERROR: Cannot connect to TJW' database. Please contact the webmaster.");
mysql_select_db($dbname);

$uresult = mysql_query("SELECT * FROM `tblFanbase` LIMIT 100");

while($row = mysql_fetch_array($uresult) {
$to = $row['email'];
$headers = 'From: Tomjwilliams.com <[email protected]>' . "\r\n" .
    'Reply-To: [email protected]' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();
$subject = "Tom Williams Update: 27th November 2008"
$message = "Hey.... message goes here"
mail($to, $subject, $message, $headers);
}

?>
 

jnjc

New Member
I would add a field to your user table called lastEmailBatch

Then have a control record recording you last batch number.

Write a script to scan the user table for users where the lastEmailBatch number does not match the control record number. Send them the email and set the lastEmailbatch field on the user. Limit your result set to 300.

Run your script every 80 minutes.

When you have a new email to send out just change the last batch number control record and your script should start sending emails again...

HTH,
JC
 

jnjc

New Member
What is your level of expertise ?

Starting at the basics do you know enough to add tables/fields ?

What is the system/site ? If it's a CMS package there may be things out there to do most of this for you....
 
Top