views:

68

answers:

2

I've got a problem with a PHP script which sends an email confirmation. When receiving the email in Thunderbird, the header comes through with the \r\n present and with the MIME type also containing the Content-type information. Hence the email renders as plain text, rather than HTML.

If I comment out the MIME type as below, the email renders correctly. Firstly, is there a significant problem doing this, and secondly, what might be causing this?

if($apptpro_config->html_email == "Yes"){
        //$headers .= 'MIME-Version:1.0\r\n';
        $headers .= 'Content-type:text/html; charset=ISO-8859-1\r\n';
    }   



    return(mail($to, $subject, $message, $headers));
+1  A: 

Make sure you enclose \r\n in double quotes (not single quotes!) so that PHP can translate that into the correct linefeed code

$header = 'MIME-Version: 1.0' . "\r\n" . 'Content-type: text/plain; charset=UTF-8' . "\r\n";

Asif Mulla
I've done this (albeit with the MIME and Content-Type on separate lines, but when the email comes through I get Content-type: text/plain; charset=UTF-8 in the top of the email body. The MIME type is set correctly in the header.
Jeepstone
Remove \r and keep only \n
Asif Mulla
<?php mail('[email protected]', 'Subject', 'Your message here', "To: The Receiver <[email protected]>\n" . "From: The Sender <[email protected]>\n" . "MIME-Version: 1.0\n" . "Content-type: text/plain; charset=iso-8859-1"); ?>
Asif Mulla
Very systematic tutorial about advance PHP mail can be found at http://articles.sitepoint.com/print/advanced-email-php
Asif Mulla
I looked at the same sitepoint article and got: $headers = "MIME-Version: 1.0\n" . "Content-type: text/html; charset=iso-8859-1"; - as you had. Thanks
Jeepstone
A: 

I know this isn't the specific answer you are looking for, but have you tried Zend Mail?

It streamlines setting up HTML emails and you can configure it to send a plain text version as well, if HTML is disabled on the clients end.

Check it out: http://framework.zend.com/manual/en/zend.mail.html-mails.html

Adam
This is actually within Joomla so it's using mail within Joomla - still php mail but within their framework so not worth adding something else.
Jeepstone