Welcome Guest, Not a member yet? Register   Sign In
Methods to send email when record is inserted
#1

[eluser]frist44[/eluser]
I'm imagining a site that has some kind of notification system. Let's say based off an alert table. When someone/something produces and alert from the site, the alert would be emailed to a particular user. Sending the actual email from the web code would be error prone it seems.

What have people done to create something like this?

Mysql trigger? Cron script that checks for new records and take action? Some kind of installed service running in the background monitoring a the alerts table?
#2

[eluser]JHackamack[/eluser]
It depends on the alert. I have the following conditions set up

People reach a 404 page (using the 404 error page I set it up to email me)

When somebody puts in the wrong information, or information that doesn't match I run a cron job every night and populate an alerts table (which is then displayed in a view to look at later)

If you want realtime alerts on if something isn't write one way to do it is create a "watcher" model that is called after you do a database insert to check. However depending on the alert you can always return the form back to the user saying the information is incorrect.

I wouldn't suggest a background monitor unless you have your own server as some hosts frown (aka will disable) that kind of behavior and i haven't found many hosts who allow triggers (then again i might not be looking that hard)
#3

[eluser]frist44[/eluser]
Gotcha. Yeah it would be a hosting situation where all that would be accessible. I probably should have been clearer. It's less about administrative type alerts, and more about alerts that a user of the site would configure and want to receive. So they might put in a request for something. If someone comes along and fulfills that request, the original "requester" should be notified. In this situation, it would be unreasonable for the "fulfiller" to submit and have the code scour the database for matching requests. So i'm just thinking something in the background would be running to make the two ends meet. Once this happens, it sends it to an "email" table. And then another scheduled task is running to just go through the "email" table every couple min or so and send the unsent ones.

that make sense?
#4

[eluser]JHackamack[/eluser]
I would probably set up a cron job to do this sort of thing. Maybe run it every hour (or half depending on the traffic to your site) that would find the matches and put an entry into the email table.




Theme © iAndrew 2016 - Forum software by © MyBB