User notification system via email
I would like to create a user notification system using emails.
In context it is for employees (user type 1) to log onto my system and enter their timesheet (hours they've worked). I would like a notification to be sent to their supervisors (also members of the 'users'
table (user type 2) that they have entered the information and it is 开发者_Go百科ready to be checked.
Currently I have a database with a table 'users'
which stores information such as 'id' (PRIMARY) AUTO INCREMENTING, 'first_name', 'last_name', 'email', 'user_type', etc
.
I know how to sent emails in PHP, and I have a fully functioning log in system however it is these notifications which I cannot get my head around with how to implement.
My current code is not Object-Oriented as it is beyond my skill level at this time.
I would like something simple, it doesn't have to be perfect. Any suggestions are greatly appreciated.
When an employee successfully enters a timesheet, can you not fetch the list of users and then send them all an e-mail? I'm guessing the timesheet is a web form, so just trigger some code when the form gets submitted.
For example:
<?php
foreach($supervisor_user as $su) {
mail(...);
}
?>
However, what might be nicer, is to periodically check (by using a cronjob
) for new timesheets and then e-mail all the supervisors about any new time sheets.
I won't write the full PHP for this, it's more of a pseudocode outline:
<?php
$last_check = /* Fetch the time we last checked for timesheets */
$new_timesheets = /* Fetch all timesheets submitted after this time */
/* Construct the e-mail message */
$message = "Hello, here are the new timesheets. \n";
foreach($new_timesheets as $ts) {
$message .= "* $ts \n";
}
/* Send a message to all supervisors */
$supervisors = /* Fetch e-mails of all supervisors */
foreach($supervisors as $s) {
mail(...);
}
/* Finally, store the time we last checked for timesheets
so that we can use this on the next run. */
?>
You might then set that to run every day, meaning that supervisors would get a single summary e-mail every day, rather than being bombarded with an e-mail for every submitted timesheet.
to spacediver - what are some of those ready made systems that would be suitable in this instance? We have the same project but feel an off the shelf system might be better for us. Please explain!
Rick
精彩评论