【发布时间】:2014-08-10 18:24:11
【问题描述】:
我的数据库中有一些邮件 ID。我必须在我在数据库中提到的某些特定日期自动向这些邮件 ID 发送邮件。如何在 php 中执行此操作。
【问题讨论】:
-
看看
crontab -
能否请您提供确切的链接
-
那么到目前为止,您为解决这个问题做了什么?
我的数据库中有一些邮件 ID。我必须在我在数据库中提到的某些特定日期自动向这些邮件 ID 发送邮件。如何在 php 中执行此操作。
【问题讨论】:
crontab
这取决于您的服务器类型。如果您使用 linux,您可以使用 cronjobs 对特定时间的特定 php 文件的执行进行编程。 如果您是托管的,您的主机可能会在他们的 cpanel 中提供一个 cronjob 菜单,否则您必须获得一个更好的托管计划来提供该菜单。或者至少可以访问您编写不同 Cronjobs 的 crontab 文件。
【讨论】:
您需要编写 cron 作业以在特定日期发送自动电子邮件。没有这个是不可能的。
语法 这是一个简单的 cron 作业:
10 * * * * /usr/bin/php /www/virtual/username/cron.php > /dev/null 2>&1
主要有两个部分:
The first part is "10 * * * *". This is where we schedule the timer.
The rest of the line is the command as it would run from the command line.
The command itself in this example has three parts:
"/usr/bin/php". PHP scripts usually are not executable by themselves. Therefore we need to run it through the PHP parser.
"/www/virtual/username/cron.php". This is just the path to the script.
"> /dev/null 2>&1". This part is handling the output of the script.
计时语法
这是 cron 作业字符串的第一部分,如上所述。它决定了 cron 作业运行的频率和时间。
它由五个部分组成:
minute
hour
day of month
month
day of week
或者
您可以在 cpanel 中设置 cron。
【讨论】:
cron 错误地输入为crone 几次。
【讨论】:
正如 Albert James 所回答的,这取决于运行应用程序的系统类型。如果是 Linux,那么您可以获得发送由 cron 作业执行的邮件的 php 脚本,如果您使用的是 Windows 机器,那么您需要使用调度任务执行该 php 脚本:How to run a PHP file in a scheduled task (Windows Task Scheduler)
如果您不想使用计划任务\cron 作业,这里还有一个选项(虽然我没有使用过):How to send schedule emails using php without cron job
【讨论】:
软件实用程序 Cron 是类 Unix 计算机操作系统中基于时间的作业调度程序。设置和维护软件环境的人员使用 cron 来安排作业(命令或 shell 脚本)以在固定的时间、日期或间隔定期运行。
【讨论】: