Linux – How to sendmail via command line piping

linuxsendmail

I have a cron command that runs a file and I'm trying to setup the output so it emails to me. I use this with 3rd party scripts that I don't want to modify the direct files, so I need to pipe the output instead of modifying the PHP.

I'm migrating from a server that uses mail to a server that uses sendmail. I'm struggling to find out how to properly send a subject to sendmail via a command line.

/usr/local/bin/php -f /path/to/file.php 2>&1 | /usr/sbin/sendmail -s "My Test Email Subject" test@email.com

Best Answer

/usr/sbin/sendmail

That's wrong.

You should have a mail command some where. It could be called mailx. Should be in the /bin/ directory. As standard practice, php scripts should never be calling anything in /sbin or /usr/sbin. The sbin programs are typically for root.

Also, php has a built in mail function.