Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 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));
like image 572
Jeepstone Avatar asked Jul 23 '26 07:07

Jeepstone


1 Answers

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";

like image 93
Asif Mulla Avatar answered Jul 25 '26 19:07

Asif Mulla



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!