I have a site setup which is for subscribers only. I have added a user expiry date field to the users section and everything is working perfectly on the front end in that I can restrict access to accounts that have already passed their expiry date.
However I need to send notification emails to accounts that expire today or will expire in 7 days time.
I am using the mailer plugin in combination with a basic plugin I have made. I have setup a basic plugin with a controller which calls the following function from the plugins service:
public function sendNotificationEmail()
{
//Create an EmailModel
$email = new EmailModel;
//Set the necessary attributes
$email->fromName = 'Joe Blogs';
$email->fromEmail = 'joe.blogs@example.com';
$email->subject = 'Email subject';
$email->htmlBody = 'The message';
//RecipientsModel
$recipients = new Mailer_RecipientsModel();
$recipients->recipients = array(
array(
'to' => 'jane.doe@example.com'
)
);
if( $recipients->validate()){
//Create mailer
craft()->mailer_main->newMailer($recipients, $email); //This will start the MailerTask
}
}
As you can see, at the moment I'm just sending a single test email each time. Everything works as expected but I've noticed that the task does not get triggered until I refresh the CP. This is a problem in my case, I think, because I want to trigger everything from a CRON job.
If anyone has any solution as to how to automatically trigger the task or if there are any alternative methods to solve this problem, I'd love to here them :)
btw, the reason I went down the task route was that the system could be sending to 100s of email addresses at a time and I didn't want to be (a) treated as spam or (b) get a timeout from the request