Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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 "bla@bla.com"
share|improve this question
add comment

2 Answers 2

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 "foo@bar.com" --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 "foo@bar.com" --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 comment

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
add comment

Your Answer

 
discard

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