现在我拥有的是什么,
1.user specified date and time in the database.
2.And also have a php script to send mail.
必需
1.trigger php script when specified date and time arrives.
Note: I am using local apache server
Example: Suppose A want to send mail to B 5 days from now, A enters date and time in database and after 5 days it will automatically send the mail by running php mailer script.
有没有办法安排这个?
答案 0 :(得分:0)
编写一个函数以从DB获取发送者和接收者列表以执行日期。
ex: check php date is equal to DB date to sent the email.
Add the php script to a cron job
检查示例代码
$queryToGetuserListToSendEmail = "select * from userlist where date_toSend_email = ''". date("Y-m-d H:i:s")."'";
$userListToSendEmail = array();//senders relievers and other details taken from DB to send emails
foreach ($userListToSendEmail as $usersToSendEmail){
//sendEmail
}
每天运行作业的Cron作业2.30 A.M(在您的cron标签中添加此内容)
30 2 * * * php /pathtoyourfile
答案 1 :(得分:0)
你现在可以在数据库中按日期使用脚本检查差异日期,间隔为1分钟或1秒,或者运行脚本检查。例如,通过php:
crontab -e
如果接近或零时间发送邮件,您可以使用检查差异时间。 现在你可以添加
` * * * * * php ~/script.php`
添加
{{1}}
通过示例运行每次检查并发送邮件