10

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.

[email protected]
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"

3 Answers 3

2

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.

2
  • 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, 2010 at 11:48
  • The CONTENT_TYPE variable solution mentioned in another answer seems to work at least in some cron versions. Oct 15, 2013 at 18:19
23

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.

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

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .