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"

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.

| 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

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

Put CONTENT_TYPE="text/html; charset=utf-8" in /etc/crontab to send the mail in HTML.

You may add it in specific file if the directory /etc/cron.d/ exists. In this case, the specification is defined only for the requested tasks.

| improve this answer | |
  • 1
    This is awesome... can confirm it works on Ubuntu 14.04.2. – billynoah Sep 18 '15 at 22:25
  • @billynoah yes, this should be the accepted answer. Works on archlinux, cronie 1.5.1-1 – g33kz0r Aug 17 '16 at 18:32
  • worked on centos – zzapper Dec 7 '16 at 15:20
  • Works in Ubuntu 16 – Marco Marsala Nov 13 '18 at 8:08
  • Doesn't appear to work on macOS Mojave. – Burhan Ali Feb 22 '19 at 10:28

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 &'); ?>
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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