Help with email Batching

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Zeteg
Forum Newbie
Posts: 1
Joined: Tue Jun 03, 2008 7:32 pm

Help with email Batching

Post by Zeteg »

My problem is that I have about 22,000 rows of emails in a mysql db. There are repeats, but I doubt there'll be too many, and I'm expecting around 17,000 distinct emails. I've contacted my webhost, and they said I'm allowed to email them all, and there are no restrictions set by them, as long as it's legal - and it is.

I wrote a script (which I posted) that searches for duplicates and then sends the email, but last time I ran it, it stopped after about 7000 emails. My friends have mentioned batching, but no one really knows how to do it. I usually would look and try to learn myself, but this is somewhat time sensitive. If anyone could help write the batching, or give me detailed instructions on what to do, I would *greatly* appreciate it!

Thanks

Code: Select all

 
<?php
 
$host = "localhost";
$user = "user";
$pass = "pw";
$dbname = "db";
 
mysql_connect($host, $user, $pass);
mysql_select_db($dbname);
 
$table = "login";
$column = "email";
$emails = array();
 
$result = mysql_query("SELECT ".$column." FROM ".$table);
$num = mysql_num_rows($result);
 
 
 
 
//Sets emails array
for($i=0;$i<$num;$i++)
{
    $row = mysql_fetch_object($result);
    if(!in_array($row->{$column},$emails))
    {
        $emails[] = $row->{$column};
    }
}
 
 
 
 
//Sends emails
 
$headers = "From: my@email.com";
//$address = "my@email.com";
$subject = "Subject";
$message = "
Email Here
";
$message = wordwrap($message, 70);
$num_sent = 0;
 
foreach($emails AS $value)
{
    mail($value, $subject, $message, $headers);
    echo "$value \n";
    $num_sent++;
}
 
echo "$num_sent";
 
 
?>
 
Post Reply