Cron/PHP/Mail

software development

#1

I have a cron to execute php files and then mails me the output. This works fine. My question is I want cron to email me the output in HTML. Currently it is just plain text.

I know when I use mail to use the code below and the email is formatted correctly.

$headers = “From: $from\r\n”;
$headers .= “Reply-To: $email \r\n”;
$headers .= ‘MIME-Version: 1.0’ . “\r\n”;
$headers .= “Content-Type: text/html; charset=‘iso-8859-1’\n”;
$headers .= “X-Mailer: PHP/”.phpversion();

So, the question is, how can I get cron to do that? Or put that information in the cron headers?

Thanks


#2

Hi

I’m not shure if I understand your problem correctly. But this header is not the header of the script, but of the mail you are sending. So you just have to add the headers to the mail function. Like this (copied from www.php.net/mail):

// To send HTML mail, the Content-type header must be set
$headers = ‘MIME-Version: 1.0’ . “\r\n”;
$headers .= ‘Content-type: text/html; charset=iso-8859-1’ . “\r\n”;

// Additional headers
$headers .= ‘To: Mary mary@example.com, Kelly kelly@example.com’ . “\r\n”;
$headers .= ‘From: Birthday Reminder birthday@example.com’ . “\r\n”;
$headers .= ‘Cc: birthdayarchive@example.com’ . “\r\n”;
$headers .= ‘Bcc: birthdaycheck@example.com’ . “\r\n”;

// Mail it
mail($to, $subject, $message, $headers);

Hope this works

Philip


#3

Thanks for your help. Maybe I did not make my original post clear. When I get the email from cron it is not formatted for HTML. What I am looking for is cron to run the script and email me the output in HTML format not in the test format as it is currently doing.