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 15 of 15
  1. #1
    Regular Coder
    Join Date
    Dec 2008
    Posts
    129
    Thanks
    0
    Thanked 0 Times in 0 Posts

    mailing list and cron

    now i want to make a mailing list .. i want to send a mail up to 2000 user. but the server only allow sending 200 mail at once so i want to make a cron job that make the following task.
    1- send mail to 200 user
    2- i have a database that have a filed name e-mail that contains mail address and
    flags field that contains zero or one
    zero -> not sent yet
    one -> e-mail sent

    3- change the flag in the database from zero to one

    4- after an hour the cron will run again and send the mail to the fields of database that have the flag zero.. and i will make the cron run until there is no flags zero so that all mails are sent..

    my problem is that i dont know how to work with cron job from PHP i want to know how to run cron Job from php??

    NOTE THAT: when the user press send button it will create the cron job for sending the 2000 mail and run every hour to send 200 mail per time ..

    can any one help me plz

  • #2
    Senior Coder
    Join Date
    Aug 2009
    Location
    Mansfield, Nottinghamshire, UK
    Posts
    1,555
    Thanks
    57
    Thanked 148 Times in 147 Posts
    not that ive tried but have you tried setting as loop to 199, setting a pause
    PHP Code:
    sleep(10
    and then resetting loop?

  • #3
    Regular Coder
    Join Date
    Dec 2008
    Posts
    129
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Phil Jackson View Post
    not that ive tried but have you tried setting as loop to 199, setting a pause
    PHP Code:
    sleep(10
    and then resetting loop?
    i did but it did not work correctly..
    could you plz send for me a sample code of what do u mean??

  • #4
    Senior Coder
    Join Date
    Aug 2009
    Location
    Mansfield, Nottinghamshire, UK
    Posts
    1,555
    Thanks
    57
    Thanked 148 Times in 147 Posts
    give me 10mins

  • #5
    Senior Coder
    Join Date
    Aug 2009
    Location
    Mansfield, Nottinghamshire, UK
    Posts
    1,555
    Thanks
    57
    Thanked 148 Times in 147 Posts
    not tested but:

    PHP Code:
    <?php
        
        $contacts 
    = array( "luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk" );
        
        
    $x=0;
        
    $z=0;
        
    $sentMsg = array();
        while(
    $x!=count($contacts) && $z<200)
        {
            if(
    $z==199)
            {
                
    sleep(2);    
                
    $z=0;
            }
            
    $to $contacts[$x];
            
    $subject 'Mail from contacts form'
            
    $headers "From: do-not-reply@actwebdesigns.co.uk\nContent-Type: text/html; charset=iso-8859-1";
            
    ob_start();
            
    //content goes below
    ?>
            <p style="margin-left:10px; color:#404040;"><small>Test from Phil Jackson created by ACT Web Designs &copy; 2009</small></p>
        
    <?php

            $message 
    ob_get_clean();
            
    $mail_sent = @mail$to$subject$message$headers );
            if(
    $mail_sent)
            {
                
    $sentMsg[] = "<span style=\"color:green\">".$to."</span><br />";
            }
            else
            {
                
    $sentMsg[] = "<span style=\"color:red\">".$to."</span><br />";
            }
            
    $x++;
            
    $z++;
        }
        
        foreach(
    $sentMsg as $output)
        {
            echo 
    $output;    
        }
        
    ?>
    Last edited by Phil Jackson; 08-26-2009 at 09:43 AM.

  • #6
    Regular Coder
    Join Date
    Dec 2008
    Posts
    129
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Phil Jackson View Post
    not tested but:

    PHP Code:
    <?php
        
        $contacts 
    = array( "luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk" );
        
        
    $x=0;
        
    $z=0;
        
    $sentMsg = array();
        while(
    $x!=count($contacts) && $z<200)
        {
            if(
    $z==199)
            {
                
    sleep(2);    
                
    $z=0;
            }
            
    $to $contacts[$x];
            
    $subject 'Mail from contacts form'
            
    $headers "From: do-not-reply@actwebdesigns.co.uk\nContent-Type: text/html; charset=iso-8859-1";
            
    ob_start();
            
    //content goes below
    ?>
            <p style="margin-left:10px; color:#404040;"><small>Test from Phil Jackson created by ACT Web Designs &copy; 2009</small></p>
        
    <?php

            $message 
    ob_get_clean();
            
    $mail_sent = @mail$to$subject$message$headers );
            if(
    $mail_sent)
            {
                
    $sentMsg[] = "<span style=\"color:green\">".$to."</span><br />";
            }
            else
            {
                
    $sentMsg[] = "<span style=\"color:red\">".$to."</span><br />";
            }
            
    $x++;
            
    $z++;
        }
        
        foreach(
    $sentMsg as $output)
        {
            echo 
    $output;    
        }
        
    ?>

    i works correctly but i have 2000 mail address and i want send 200 per time..
    2- if close the page (in IE) will it send the mail to the rest of peoples or it will stop sending mails?

    so that's why i think of using CRONJOB

  • #7
    Senior Coder
    Join Date
    Aug 2009
    Location
    Mansfield, Nottinghamshire, UK
    Posts
    1,555
    Thanks
    57
    Thanked 148 Times in 147 Posts
    how often will you be sending these emails?

  • #8
    Regular Coder
    Join Date
    Dec 2008
    Posts
    129
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Phil Jackson View Post
    how often will you be sending these emails?
    it is a newsletter mail .. so i have 2000 members in registered in the database..

    the server allow only sending 200 mail per time .. so i can not send the 2000 mail at a time

    so i thinked about sending the mails using cron Job instead of updating falgs and send to those who's it flags = 0 and those who have a flag =1 will not sned again the mail to them

    now i will try to use your code with a huge number of user and try to close it when sending to see if it will send the rest of the people or not..

    really thnx alot for ur help ,
    and if u have another idea plz tell me

  • #9
    Senior Coder
    Join Date
    Aug 2009
    Location
    Mansfield, Nottinghamshire, UK
    Posts
    1,555
    Thanks
    57
    Thanked 148 Times in 147 Posts
    I dont know if cronjobs are your answer to your problem, i.e. if one works (lets say the code i just wrote) then it will work as a cronjob.

    Cronjob is just going to a page, without having to manually go there.

  • #10
    Regular Coder
    Join Date
    Dec 2008
    Posts
    129
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Phil Jackson View Post
    I dont know if cronjobs are your answer to your problem, i.e. if one works (lets say the code i just wrote) then it will work as a cronjob.

    Cronjob is just going to a page, without having to manually go there.
    MR Phil Jackson i mean that the user does not have to wait untill it sends the 2000 mail... so if he will close the browser or go to another page... will it stop sending the maill to tthe 2000 user or it will complete sending even if he closed the browser..DO GOT MY QUESTION?

  • #11
    Senior Coder
    Join Date
    Aug 2009
    Location
    Mansfield, Nottinghamshire, UK
    Posts
    1,555
    Thanks
    57
    Thanked 148 Times in 147 Posts
    O how rude lol, I THINK, and just a thought, the script will still run as long as there is no output to the browser.

  • #12
    Regular Coder
    Join Date
    Sep 2009
    Location
    Calgary, Alberta
    Posts
    239
    Thanks
    47
    Thanked 3 Times in 3 Posts
    how can you place your db emails list to this array.?

    PHP Code:
     $contacts = array( "luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk" ); 

    Thanks, S.

  • #13
    Regular Coder
    Join Date
    Dec 2008
    Posts
    129
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by SlayerACC View Post
    how can you place your db emails list to this array.?

    PHP Code:
     $contacts = array( "luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk""luke@actwebdesigns.co.uk" ); 

    Thanks, S.
    by using array push function

  • #14
    Regular Coder
    Join Date
    Sep 2009
    Location
    Calgary, Alberta
    Posts
    239
    Thanks
    47
    Thanked 3 Times in 3 Posts
    and if you are unaware how to do that..??

    could you fill me in.?

    Thanks, S.

  • #15
    Senior Coder djm0219's Avatar
    Join Date
    Aug 2003
    Location
    Wake Forest, North Carolina
    Posts
    1,292
    Thanks
    4
    Thanked 202 Times in 199 Posts
    Dave .... HostMonster for all of your hosting needs


  •  

    Posting Permissions

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