How to sendmail via command line piping

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" [email protected]

/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.


On my Debian systems (which have Exim rather than "real" sendmail, but still have a sendmail binary for compatibility), when I want to send mail from a script I do something equivalent to:

cat <<EOF | sendmail -t
To: [email protected]
Subject: Testing
From: [email protected]

This is a test message
EOF

Note that the blank line is important.