Send E-mail in some period of time (monthly) [ octobercms ]

165 Views Asked by At

I'm developing an enrolment system in Octobercms. I need to check(DB) who has not paid for the enrolments they have enrolled at the end of the month. And then send an email to the customer informing them to pay. If onSendDueEmails() is the function, how to call this at the end of the month?.

note: I tried cronjobs but feels like cronjobs isn't a good solution

1

There are 1 best solutions below

0
Vince On

You mentioned that you have tried cronjobs. I wonder if that means you have also tried OctoberCMS's solution for scheduling tasks...? I have found it to be very robust and easy to use. It is an elegant alternative to having a separate crontab entry for each scheduled task, which can quickly become unmanageable. Here is a simple example of how to use the task scheduler:

  1. To setup the scheduler, add this one simple job to your server's crontab (see docs):
* * * * * php /path/to/artisan schedule:run >> /dev/null 2>&1

NOTE: Be sure to replace /path/to/artisan with your server's absolute path to the artisan executable. (This should be the same path as your OctoberCMS project's root path)


  1. In your plugin's Plugin.php file:
class Plugin extends PluginBase
{
    ...

    public function registerSchedule($schedule)
    {
        $schedule->call(function () {
            onSendDueEmails();
        })->monthly();
    }
}

You can schedule however many tasks you wish in your plugin's Plugin.php file. I hope this is helpful!