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]
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:
Note that the blank line is important.
That's wrong.
You should have a
mail
command some where. It could be calledmailx
. 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.
echo = The body of the email.
sed stuff = Applies the email headers, and important double-line between body and headers.
sendmail -t = Pipes it directly through sendmail.