user3426191
user3426191

Reputation: 71

Cronjob for automatic email?

I'm not sure what to do.

I have to tabels, one with user emails and one with upcoming events.

The event table contains a date for when the event is going to happen, and i wanna notify the user who is attending the event via email.

should i make a cron job? or is there another and better way to do it?

Upvotes: 0

Views: 45

Answers (1)

Oldskool
Oldskool

Reputation: 34837

You can create a cronjob for this, yes. If you want to notify the users one day prior to the event, you can just add a cronjob that runs daily and checks all events for the next day, something like:

<?php
$tomorrowsEvents = $databaseResultsHere; // Insert actual db results here ;-)
foreach ($tomorrowsEvents as $event) {
    $attendees = $attendeesFromDatabase; // Also insert a real db result here
    foreach ($attendees as $attendee) {
        mail($attendee['email'], 'Your event is tomorrow', 'Have fun!');
    }
}

Just run that daily and you can simply mail all your users at that moment.

Upvotes: 1

Related Questions