Help with email Batching
Posted: Tue Jun 03, 2008 7:37 pm
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
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";
?>