Page 1 of 1

doing a cron job (5th post)

Posted: Sun Jul 22, 2007 12:45 pm
by m2babaey
Hi
You have seen some sites email members that their account is going to expire in 1 week send email notifications.
Do that sites check the whole database everyday?
secondly, how to send mass mail with php?
thanks

Posted: Sun Jul 22, 2007 12:55 pm
by Benjamin
You can run a cron job every night that queries the database for members expiring within x number of days, sends them an email, then sets a database field such as "expire_notified" to 1 for true.

You can use swiftmailer for mass mailings.

Posted: Sun Jul 22, 2007 1:38 pm
by m2babaey
if it is my own site, i may search the database manually every night.
but when I'm going to do it for my client I should set it to work automatically ( it's not a project of my client! i have no customer right now! i just wana learn. thanks)

Posted: Sun Jul 22, 2007 6:54 pm
by dirkr
thats what the cron job would do..
http://en.wikipedia.org/wiki/Cron

just write a php script that does a check for the accounts . .and call that script with a cronjob that will run daily or whenever you want

Posted: Tue Jul 24, 2007 6:07 am
by m2babaey
Thanks ( first i thought cron means stupid! :lol: :lol: :oops: )
I saw cron job in my cpanel
There I can choose the time for the job. and just remains the command input field.
It that going to be filled with a sql statement?
please give me a sample command line assuming database articles with username: m2babaey and password: pass123
I really need it :roll:
I wish I could insert the following code in the command field:

Code: Select all

<?php
$result=mysql_query("select* from table where expiredate-7<now()");
while($row=mysql_fetch_array($result)){
mail( $row['email'] , "Reminder" , "Please act for rebilling ASAP" , "admin@billing.com");
}
?>
Is it possible?
and one other thing will I need swift mailer If I use cron job to mail?
Thanks

Posted: Tue Jul 24, 2007 8:25 am
by m2babaey
I learnt something
I will create a php file with the code above and save it in my root directory ( or should I save it in public html?)
Then How can I call that php file to be executed? ( what should be the command line?)

Posted: Tue Jul 24, 2007 8:29 am
by s.dot
Put something similar in your command field

Code: Select all

/usr/bin/php /path/to/cron.php
The first part should be the path that contains your php executable, the second part should be the absolute path to the php cron script.

Posted: Tue Jul 24, 2007 8:42 am
by m2babaey
seperated by spaces?