700Part IVConnectionsListing 37-8(continued) $from = mailbot@example.com ; $subject = Evaluation software license expires ; $msg = You downloaded our evaluation software 45 daysago. Now you should pay us, or it will self-destruct. ; $mailsend = mail($to, $subject, $msg, From: $from ); $send_info_email_arr .= n .$to. n ; } // Send me some email to let me know what happened$info_msg .= I sent mail to the following evaluatorstoday:
n ; $info_msg .= print_r($send_info_email_arr); $info_mail = mail( webdev@example.com , Cron job for$target_date , $info_msg, From: cronjob@example.com ); } else { // If there were no recipients today, let me know that$info_msg = I didn t find anyone to send mail to today. ; $info_mail = mail( webdev@example.com , Cron job for$target_date , $info_msg, From: cronjob@example.com ); } ?> Save this file in a location and with permissions that allow the PHP binary user to run it. Now you need to schedule your cronjob. Say we want to send this mail out once a day at3:15 a.m., the slowest hour of the day for your Web servers. Open up your crontab(typecrontab-ein a shell) and enter this line (make sure your Unix user can execute the PHPbinary): 15 03 * * * /usr/local/bin/php /home/phpcrons/nagmail.phpReading from left to right, the various notations stand for minute, hour, day, month, day ofweek, and the command to be executed. (Asterisks are wildcards.) So this line tells the crondaemon to wake up and tap the PHP binary to run the nagmail.phpscript at 3:15 a.m. everymorning of the year. So sad for Windows users, but this is not possible with PHP in your operating system. Unixhas a lot of functionality in the system layer that Windows tends to put in the applicationlayer so for instance Unix programmers constantly use the greputility to search for a stringin a set of files, which Windows programmers accomplish in the IDE. Similarly, scheduling arepetitive task like sending automatic e-mail is done in Outlook on Windows or as a triggerfrom SQL Server, rather than via a cronjob. Caution42
Note: In case you are looking for affordable and reliable webhost to host and run your j2ee application check Vision J2ee Web Hosting services.