Daily report to email

By ross - October 31, 2016

Hi Tim

What I would do is setup a custom script using the cron system in CMS Builder. The script can be scheduled to run once a day.

The first step is to take the script you already created and add the email components to it.

This will involve setting up an email template and then using the function sendMessage().

Are you familiar with our sendMessage() function and how to have it use an email template?

After that, we can look at how to have this script run automatically via cron.

Does that all make sense?

Let me know any questions.

Thanks.

-----------------------------------------------------------
Cheers,
Ross Fairbairn - Consulting
consulting@interactivetools.com

Hire me! Save time by getting our experts to help with your project.
Template changes, advanced features, full integration, whatever you
need. Whether you need one hour or fifty, get it done fast with
Priority Consulting: http://www.interactivetools.com/consulting/

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