...

View Full Version : email list help



jclay12345
01-01-2007, 09:13 PM
I have an email list full of email addresses. I have a loop to send out html emails to each subscriber individually. My list has grown and I found out that I can only send 750 emails per 15 minute period. Does anyone have any ideas how I can incorporate this limitation into my loop so that I won't have to do it manually?

jclay12345
01-02-2007, 01:29 AM
ok, here is what I'm thinking, but I have no idea how to do it in php. I know php, but I don't know how the time functions work.



//open file with email addresses
$fp = fopen( "emaillist.txt", 'r' );

$loopcount = 0;
$start_time = time(); //set to current time
while (not the end of file)
{
for(int $i = $loopcount * 750; i <= ($loopcount + 1) * 750; $i++)
{
if(not the end of file)
{
$line = fgets( $fp, 1024 ); //read line (email address) from file
// send mail here
}
}
$loopcount++;

$cur_time = time(); //set to current time

$time_passed = $cur_time - $start_time; //HOW DO YOU SUBTRACT TIME???

if ($time_passed < 15 minutes) //HOW DO YOU TELL IF IT'S LESS THAN 15 MINUTES???
{
pause for 15 minutes - $time_passed //HOW DO YOU DO THIS???
}
}



Please help. If I'm wrong in my logic in anyway, please let me know that as well. Thanks.

dumpfi
01-02-2007, 04:09 PM
<?php
define('ADDRESS_FILE', 'emaillist.txt');
define('EMAILS_PER_ROUND', 750);
define('SLEEP_PERIOD', 15 * 60);
define('SLEEP_PERIOD_REMAINDER', 60);

ini_set('max_execution_time', 0);

function sendMessage($message)
{
echo $message;
flush();
}
//open file with email addresses
$fp = fopen(ADDRESS_FILE, 'r');
if(!$fp)
{
die('Unable to open address file.');
}

sendMessage('Starting..<br>');

$rounds = 0;
$i = 1;
$remainders = ceil(SLEEP_PERIOD / SLEEP_PERIOD_REMAINDER);

while(!feof($fp))
{
sendMessage('Sending out email '.$i.' to '.($i + EMAILS_PER_ROUND - 1).'.<br>');
flush();
++$rounds;
for($max = EMAILS_PER_ROUND * $rounds; $i <= $max; ++$i)
{
$line = fgets($fp);
if(FALSE === $line)
{
die('Error while retrieving address number '.$i);
}
// send mail here

if(feof($fp))
{
sendMessage('Reached end of file after address number '.$i.'.<br>');
break 2;
}
}
sendMessage('Going into sleep mode..<br>');
if(1 > $remainders)
{
sendMessage('Sleeping for '.SLEEP_PERIOD.' seconds.<br>');
sleep(SLEEP_PERIOD);
}
else
{
$sleepTime = SLEEP_PERIOD;
for($j = 0; $j < $remainders; ++$j)
{
sendMessage('Sleeping for '.($sleepTime).' seconds.<br>');
sleep(min(SLEEP_PERIOD_REMAINDER, $sleepTime));
$sleepTime -= SLEEP_PERIOD_REMAINDER;
}
}
sendMessage('Going out of sleep mode..<br>');
}

sendMessage('Finished sending out emails.<br>');
?>To make this script work you'll likely need to increase the value of the timeout directive of your web server, too (e.g. Apache's defaults to 300 seconds). Read their documentation on how to do this.

dumpfi

jclay12345
01-03-2007, 03:49 AM
Thanks. I tested your script and it's not looping. I think it may have something to do with the for loop. I'll double check.

mlseim
01-03-2007, 04:27 AM
Do you have the ability to use a CRON service to schedule
script runs at regular intervals? If so, you could have a PHP script
copy the list to a temp file, and another PHP script runs every 30
minutes, lopping off 500 emails at a time, sending them and then it
exits the program ... returns again in 30 minutes and gets the next 500
emails, until they are all gone. If no emails exist in the temp file, the
script just exits until the file is reset. Simply putting the emails back
into the temp file starts it all over again.

If you don't have a CRON service, you could rely on people visiting
your site to trigger the script. A PHP script checks the last time it
ran to make sure it's been at least 30 minutes since the last run,
if so, it lops-off the next 500 emails from the temp file and sends them.
This of course relies on people visiting your site, but if you know you'll
get a visitor at least every 30 minutes, it would be the same as an
automatic CRON job.


.

dumpfi
01-03-2007, 04:33 PM
Thanks. I tested your script and it's not looping. I think it may have something to do with the for loop. I'll double check.I've tested it and it does work correctly.

If you close the browser window while the script executes, you must put ini_set('ignore_user_abort', TRUE); before the script.

If you didn't close the browser window, make sure that the Timeout directive of your server is set up correctly, so the server doesn't kill the process while the script is still executing.

dumpfi

bubbles19518
01-03-2007, 04:44 PM
in your mail() function send an email to a dummy email ex: mailbot@you.com. Then Blank Carbon Copy it to everyone on your mailing list.

mlseim
01-03-2007, 07:33 PM
Bubbles ...

I tried that "blind carbon copy" trick with my webhost and they
didn't buy it. Each email was still counted. But it's worth a try.

jclay12345
01-03-2007, 07:43 PM
I must be missing something. I changed EMAILS_PER_ROUND to 2 and I changed SLEEP_PERIOD to 1 * 60. I put three emails in my emaillist file. This is what I got.

Starting..
Sending out email 1 to 2.

Mail Sent To test@myserver.com

Mail Sent To
Reached end of file after address number 2.
Finished sending out emails.

It couldn't have timed out that fast could it?

jclay12345
01-03-2007, 07:45 PM
in your mail() function send an email to a dummy email ex: mailbot@you.com. Then Blank Carbon Copy it to everyone on your mailing list.

what's the purpose of this.

dumpfi
01-03-2007, 09:50 PM
I must be missing something. I changed EMAILS_PER_ROUND to 2 and I changed SLEEP_PERIOD to 1 * 60. I put three emails in my emaillist file. This is what I got.

Starting..
Sending out email 1 to 2.

Mail Sent To test@myserver.com

Mail Sent To
Reached end of file after address number 2.
Finished sending out emails.

It couldn't have timed out that fast could it?No. feof must've reported that the end of the file was reached after reading 2 lines of the file.

When I tested it, I was able to echo out a file of ~1,5k lines line by line. I really don't know why it doesn't work for you.

dumpfi

jclay12345
01-05-2007, 02:18 PM
I dont know what's wrong with mine then. I will retry tonight. thanks.

jclay12345
01-07-2007, 12:40 AM
ok, you were right. It works. I'm stupid. I did something dumb so it wasn't working right. But I got it working now. Thanks. I really do appreciate it.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum