Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 13 of 13

Thread: email list help

  1. #1
    New to the CF scene
    Join Date
    Jan 2007
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    email list help

    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?

  • #2
    New to the CF scene
    Join Date
    Jan 2007
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

    Code:
    //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.

  • #3
    Regular Coder
    Join Date
    Jun 2004
    Posts
    565
    Thanks
    0
    Thanked 18 Times in 18 Posts
    PHP Code:
    <?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(
    $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
    Last edited by dumpfi; 01-02-2007 at 03:15 PM.
    "Failure is not an option. It comes bundled with the software."
    ....../)/)..(\__/).(\(\................../)_/)......
    .....(-.-).(='.'=).(-.-)................(o.O)...../<)
    ....(.).(.)("}_("}(.)(.)...............(.)_(.))Ż/.
    ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ
    Little did the bunnies suspect that one of them was a psychotic mass murderer with a 6 ft. axe.

  • #4
    New to the CF scene
    Join Date
    Jan 2007
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #5
    Master Coder mlseim's Avatar
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,369
    Thanks
    8
    Thanked 1,075 Times in 1,066 Posts
    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.


    .
    Last edited by mlseim; 01-03-2007 at 03:29 AM.

  • #6
    Regular Coder
    Join Date
    Jun 2004
    Posts
    565
    Thanks
    0
    Thanked 18 Times in 18 Posts
    Quote Originally Posted by jclay12345 View Post
    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
    "Failure is not an option. It comes bundled with the software."
    ....../)/)..(\__/).(\(\................../)_/)......
    .....(-.-).(='.'=).(-.-)................(o.O)...../<)
    ....(.).(.)("}_("}(.)(.)...............(.)_(.))Ż/.
    ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ
    Little did the bunnies suspect that one of them was a psychotic mass murderer with a 6 ft. axe.

  • #7
    Regular Coder
    Join Date
    Sep 2006
    Location
    Colorado
    Posts
    132
    Thanks
    7
    Thanked 1 Time in 1 Post
    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.
    -bubbles

  • #8
    Master Coder mlseim's Avatar
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,369
    Thanks
    8
    Thanked 1,075 Times in 1,066 Posts
    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.

  • #9
    New to the CF scene
    Join Date
    Jan 2007
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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?

  • #10
    New to the CF scene
    Join Date
    Jan 2007
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by bubbles19518 View Post
    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.

  • #11
    Regular Coder
    Join Date
    Jun 2004
    Posts
    565
    Thanks
    0
    Thanked 18 Times in 18 Posts
    Quote Originally Posted by jclay12345 View Post
    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
    "Failure is not an option. It comes bundled with the software."
    ....../)/)..(\__/).(\(\................../)_/)......
    .....(-.-).(='.'=).(-.-)................(o.O)...../<)
    ....(.).(.)("}_("}(.)(.)...............(.)_(.))Ż/.
    ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ
    Little did the bunnies suspect that one of them was a psychotic mass murderer with a 6 ft. axe.

  • #12
    New to the CF scene
    Join Date
    Jan 2007
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I dont know what's wrong with mine then. I will retry tonight. thanks.

  • #13
    New to the CF scene
    Join Date
    Jan 2007
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •