...

View Full Version : mailing list and cron



john_zakaria
08-26-2009, 09:43 AM
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

Phil Jackson
08-26-2009, 09:56 AM
not that ive tried but have you tried setting as loop to 199, setting a pause

sleep(10)
and then resetting loop?

john_zakaria
08-26-2009, 10:11 AM
not that ive tried but have you tried setting as loop to 199, setting a pause

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??

Phil Jackson
08-26-2009, 10:14 AM
give me 10mins

Phil Jackson
08-26-2009, 10:36 AM
not tested but:



<?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;
}

?>

john_zakaria
08-26-2009, 10:54 AM
not tested but:



<?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

Phil Jackson
08-26-2009, 11:02 AM
how often will you be sending these emails?

john_zakaria
08-26-2009, 11:16 AM
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

Phil Jackson
08-26-2009, 11:24 AM
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.

john_zakaria
08-26-2009, 11:29 AM
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?

Phil Jackson
08-26-2009, 11:36 AM
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.

SlayerACC
11-10-2009, 06:40 PM
how can you place your db emails list to this array.?


$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.

john_zakaria
11-11-2009, 07:24 AM
how can you place your db emails list to this array.?


$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

SlayerACC
11-11-2009, 06:30 PM
and if you are unaware how to do that..??

could you fill me in.?

Thanks, S.

djm0219
11-11-2009, 07:56 PM
http://us.php.net/manual/en/function.array-push.php



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum