Linux – Sending an email via cron

centoscronlinuxPHPsql

I'd like some advice on how best to send an email after running a SQL query. Every day, I would like to run a PHP/SQL script to identify users who should be emailed. After this runs, I would like to email those users and attach a file for each user (which is the output of another PHP/SQL process).

My approach thus far is to use use cron to call the php script and to write the csv output to a unique temporary directory for each user. However, I'm not sure how best to email the users this data.

I'm using a CentOS server and using PostGreSQL for my database.

Best Answer

Best way is to send the mail via your php code (http://php.net/manual/en/function.mail.php). Cron can only have one mail recipient per crontab entry (Override MAILTO for a single crontab entry).