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

I have a stats program which runs on log files via cron. The stats program can output HTML.

Right now I rely on the MAIL_TO mechanism in the crontab.

55 23 * * * /usr/bin/htmlstats

The problem is that I want the email sent to display as HTML and not as plain text.

Cron places the following header in the email:

Content-Type: text/plain; charset="UTF-8"

Any idea how I would change this to:

Content-Type: text/html; charset="UTF-8"
share|improve this question

4 Answers 4

up vote 3 down vote accepted

I don't think you can. A solution could be to pipe the output to sendmail or mail, which gives you more control over content type and other headers.

share|improve this answer
Thanks. I gave the piping to mail a go and I'm happy with what I'm seeing. All the best! –  Mark L Jan 13 '10 at 11:48
The CONTENT_TYPE variable solution mentioned in another answer seems to work at least in some cron versions. –  Peter Eisentraut Oct 15 '13 at 18:19

YES, you can.

<?php exec('(  echo "test<br>créer un mail"| mail -s "SUBJECT" -a "Content-Type: text/html; charset=UTF-8" '.$receiver.' -- -f '.$sender.' ) &> /dev/null &'); ?>
share|improve this answer

I have the same question. When I pipe to mail (via a script), I still get unformatted html in my mailbox. How do you change the headers?

php -q www/training.php | mail -s testing me@somewhere.com

share|improve this answer
php -q www/training.php | mail -s testing -a 'Content-Type: text/html; charset="UTF-8"' me@somewhere.com –  Mark L Mar 4 '10 at 19:53

I put the CONTENT_TYPE="text/plain; charset=utf-8" variable to have my mail in UTF-8.

I think you put CONTENT_TYPE="text/html; charset=utf-8" in crontab to send the HTML in header.

share|improve this answer
So how would I do this? Are these variables CRON is looking for or something? –  Mark L Jan 15 '10 at 11:15
OOps sorry, I forgot to say where you put that : add this line in your /etc/crontab. Cron read it and then add the line in the mail header. –  Dom Jan 15 '10 at 13:41

Your Answer


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

Not the answer you're looking for? Browse other questions tagged or ask your own question.