Send report via email? Ahmed Gad April 07, 2018 22:00 3 comments Is there an option to send report(s) via email to the admin regularly at a specific time? Thanks! Comments 3 comments Sort by Date Votes Chris Muench April 09, 2018 13:47 Official comment As of now there isn't a way. Martin Roy December 14, 2018 20:03 Would a cron job handle something like that? 0 Chris Muench December 14, 2018 20:36 You would setup a cron task and use https://wkhtmltopdf.org to generate an email Here is an example of creating an email controller that can then be run on a cron (php index.php email_reports index) <?phpclass Email_reports extends CI_Controller{ function index() { $exes = array(); $exes[] = 'c:\PROGRA~1\wkhtmltopdf\bin\wkhtmltopdf.exe'; $exes[] = '/usr/local/bin/wkhtmltopdf'; $tmp = APPPATH.'../tmp'; $reports_username = $this->config->item('reports_username'); $reports_password = $this->config->item('reports_password'); $reports_base_url = $this->config->item('reports_base_url'); foreach($exes as $exe) { if (is_executable($exe)) { if ($exe == 'c:\PROGRA~1\wkhtmltopdf\bin\wkhtmltopdf.exe') { $report_url = escapeshellarg($reports_base_url."index.php/reports/generate/closeout?report_type=simple&report_date_range_simple=TODAY&export_excel=0"); $login_url = escapeshellarg($reports_base_url."index.php/login"); } else { $report_url = $reports_base_url."index.php/reports/generate/closeout?report_type=simple&report_date_range_simple=TODAY&export_excel=0"; $login_url = $reports_base_url."index.php/login"; } shell_exec("$exe --post username $reports_username --post password $reports_password --cookie-jar $tmp/reporting.jar $login_url $tmp/dumb.pdf"); shell_exec("$exe --print-media-type --orientation Portrait --cookie-jar $tmp/reporting.jar '$report_url' $tmp/closeout.pdf"); //e-mail $reports_email = $this->config->item('reports_email'); $this->load->library('email'); $config = array(); $config['mailtype'] = 'text'; $this->email->initialize($config); $this->email->from($reports_email); $this->email->to($reports_email); $this->email->subject('Daily Reports'); $this->email->message('Attached are your daily reports'); $this->email->attach("$tmp/closeout.pdf", 'attachment', 'closeout.pdf'); $this->email->send(); unlink($tmp.'/closeout.pdf'); unlink($tmp.'/dumb.pdf'); unlink($tmp.'/reporting.jar'); break; } } }}?> 0 Please sign in to leave a comment.
Comments
3 comments
As of now there isn't a way.
Would a cron job handle something like that?
You would setup a cron task and use https://wkhtmltopdf.org to generate an email
Here is an example of creating an email controller that can then be run on a cron (php index.php email_reports index)
Please sign in to leave a comment.