Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am running the cron job where there is html formatted output. I want to send that output my email address in html format.

Is there any way to do that

php  /home/bla/bla_bla.php | mail -s "Bla Bla"  -s ""
share|improve this question
up vote 0 down vote accepted

You might want to take a look at mime-construct. It's handy for just this kind of thing. I use it to send a generated HTML doc as part of a daily cronjob like so:

/usr/bin/mime-construct --to "" --subject "My daily html foo" --multipart multipart/alternative --type text/html --file htmlfiletosend.html

If you don't care about the messages being multipart, you can drop that portion. It can also take the html via stdin like so:

php your_script.php | mime-construct --to "" --subject "Foo Report" --type text/html --file -

I don't know what distro you're using, but this is available in the main repositories for Debian and Ubuntu, I would imagine RHEL and derivatives likely have it too.

share|improve this answer
that looks good – John Oct 13 '10 at 1:35

Add a Content-Type header such as -a 'Content-Type: text/html; charset="iso-8859-1"' or use a mail client that guesses the Content-Type (GNU mailutils for example probably do that).

share|improve this answer
How can i add content type in command line like above case – John Oct 12 '10 at 11:40
Depends on the mail implementation you're using. BSD mail: -a, sendmail: (echo -e "Header: Value\n"; php bla_bla.php) | mail …. Just look it up in the man page. – al. Oct 12 '10 at 12:01

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.