简体   繁体   中英

Automatic Send E-mail PHP After Several Months

I am creating a system that could send and e-mail to client when their payment need to pay. I have a DB that contain their status. If their status is 10 month, it will send an alert email to my client. I know the function of mail() but how to do this function work after 10 month of last my client payment?

Why dont use Cron ? You need to set the mail code (like mail.php) to run every 10 months, for that cron is designed.

Cron format looks like:

minute hour day_of_month month day_of_week command_you_want_to_execute

Example

If you want to run a program in 15:31, day 06 in month 09, the cron will be:

31 15 06 09 * /path/to/file.php

Run the Cron

Important for us to remember that php is a deciphered language and the php engine is it deciphers and executes our code. The software we need to run practice it is not our script, is our php engine and tell him to perform the code is written to the file. Usually the end result will look like this:

* * * * * php -f /path/to/file.php

Where should i write this

Crontab file is a file of the operating system. Users do not always have access to it, but you can write the commands through the panel of the storage company.

$date1 = $lastpaymentdate;
$date2 = date('Y-m-d');

$ts1 = strtotime($date1);
$ts2 = strtotime($date2);

$year1 = date('Y', $ts1);
$year2 = date('Y', $ts2);

$month1 = date('m', $ts1);
$month2 = date('m', $ts2);

$diff = (($year2 - $year1) * 12) + ($month2 - $month1);
if($diff > 9){
// send mail    
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM