I have written a function which receives some parameters (email addresses) and send email. I need this to be executed on a user action like follows-
Somebody answers a question, an HTTP request to add the question, a controller receives the request and adds the question to the database. Now I want that I call the function to send email but not wait it to complete – so returning the HTTP response.
How can I do this?
I would add a column to the database – a boolean or timestamp – which indicates whether or not an email has been sent. Then set up a cron job to send emails for those records.
This also makes it easier to limit the # of emails being sent at a time.