Using PHP mail - setting correct MIME type
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 MI开发者_开发知识库ME 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));
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";
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
精彩评论