Daily report to email

By Toledoh - October 18, 2016

Hi Guys,

No rush on this one - just hoping to get some direction.

I want to create a plugin that runs daily, and sends an email to a chef on how many booking / meals etc there are for the kitchen the next day.

I've got a report viewable via a URL that lists each booking for the queried date range, then totals the numbers at the end.  I want to send those total in an email.

How would I go about setting that up?

Cheers,

Tim (toledoh.com.au)

By Dave - October 31, 2016

Hi All, 

Tim had us build a simple script for him to do this and said we could post it here in case it was helpful to anyone else.

I've attached a plugin "Automated Email Report" which sends out an email at 3am nightly. 

It has links in the plugin menu to "Preview Email", to show what would be sent, and "Send Now" to send a test message immediately.

How it works is it takes the content returned by the aem_previewEmail() function and emails it.  So in that function you can require another PHP file with a viewer, add some getRecords code, or whatever you need.

You can customize the time it sends out the email with this line (which has instructions above it):
addCronJob('aem_sendNow', "Automated Email Report", '0 3 * * *');      // Run at 3am every day

You can customize the from/to/subject with these lines:

'from'    => "user@example.com",
'to'      => "user@example.com",
'subject' => "Daily Report",

And you can customize the contents of the email by adding code to aem_previewEmail();

Hope that helps!

Dave Edis - Senior Developer
interactivetools.com