简体   繁体   English

几个月后自动发送电子邮件PHP

[英]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. 如果他们的状态是10个月,它将向我的客户发送警报电子邮件。 I know the function of mail() but how to do this function work after 10 month of last my client payment? 我知道mail()的功能,但是在上一次客户付款10个月后该功能如何工作?

Why dont use Cron ? 为什么不使用Cron You need to set the mail code (like mail.php) to run every 10 months, for that cron is designed. 您需要将电子邮件代码(例如mail.php)设置为每10个月运行一次,因为该cron是经过设计的。

Cron format looks like: Cron格式如下:

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: 如果您想在第9个月的第06天15:31运行程序,那么cron将为:

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. 重要的是,请记住php是一种解密语言 ,而php引擎则是解密并执行我们的代码。 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. 我们需要运行练习的软件不是我们的脚本,而是我们的php引擎,并告诉他将执行的代码写入文件。 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. Crontab文件是操作系统的文件。 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    
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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