schedule an email in php

我们两清 提交于 2019-12-17 17:16:34

问题


I want to schedule sending of email from php script. I want user to specify date and time and then on the specified date and time, I want those emails to be sent automatically. How do I implement it? I am working on codeigniter.


回答1:


One way to do it would be to create a "scheduled_emails" database table. Put all the emails you want to queue in there, including columns such as, recipient, subject, message and optional headers.

You could then set up a script to look at that table and send any emails that have a "send_time" which is greater than the current time. You could then set up a cron job to run this script every.. 5 minutes for example.




回答2:


PHP usually uses an external scheduler for this sort of thing. That means cron on *nix or Windows Task Scheduler on Windows.

If you want to set it up through a web interface, then you might consider storing your schedule in a database and having cron (etc) kick off a script that looks for overdue emails every 5 minutes.



来源:https://stackoverflow.com/questions/12893499/schedule-an-email-in-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!