note 11157 deleted from function.mail by jimw
| From: | jimw@php.net | Date: | Wed, 31 Oct 2001 23:12:42 +0000 |
| Subject: | note 11157 deleted from function.mail by jimw | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-19895@lists.php.net to get a copy of this message | ||
With the following code you can easily make a mailing list tool that will email a large list without
timing out. It does this by using Javascript to send 10 emails at a time, while telling the user to
meanwhile keep the browser open.
You must pass the variables $start and $total through the URL. I suggest running a query on the
database to get the total number of emails (using mysql_num_rows) and pass the result to this page.
A sample url would be www.yourserver.com/email.php?start=0&total=60.
Obviously you have to name the file email.php and the variable total (in this case 60) has to come
from the mysql_num_rows result. You also have to connect to the right database : )
if ($start < $total) {
if (($increment + 10) > $total) $increment = $total;
else $increment = 10;
$query = mysql_query("select email from mailinglist limit
".addslashes($start).", $increment");
if (($start + 10) > $total) $end_count = $total;
else $end_count = $start + 10;
$begin_count = $start + 1;
echo "Sending email $begin_count through $end_count out of $total.\n";
echo "<h3>PLEASE KEEP THE BROWSER OPEN</h3>\n";
while ($result = mysql_fetch_array($query)) {
$mailme = stripslashes($result[email]);
mail($mailme,"subject", "fine", "From:
steve@zoomedia.com");
}
echo "<script language=\"javascript\">\n";
echo "<!--\n";
echo "window.location.href = \"http://$HTTP_HOST$PHP_SELF?start=$end_count&total=$total\"\n";
echo "// -->\n";
echo "</script>\n";
}
I got the idea for this from Postlister. Postlister is a nice mailing list manager for small to
medium sized lists. It is written in PHP and thus you can muss it all up to suit you own outlandish
desires. Download it from freshmeat.net or look at the homepage at http://sourceforge.net/projects/postlister
Enjoy.