Page 1 of 1

HTML email, good in Gmail but random string in iMail/Outlook

Posted: Fri Nov 19, 2010 12:01 pm
by $var
Hello DevNet,
I am using a function that I found to send html formatted emails. I plunked it in and it worked with no issue. Until it was tested by someone using Outlook or iMail, who got a LONG string of indecipherable data. I am using Gmail as my mail client, and I happily/ignorantly getting the nicely formatted emails.

The function:

Code: Select all

//MAILING FUNCTION
function sendHTMLemail($HTML,$from,$to,$subject)
{
    $headers = "From: $from\r\n"; 
    $headers .= "MIME-Version: 1.0\r\n"; 
    $boundary = uniqid("HTMLEMAIL"); 
      
    $headers .= "Content-Type: multipart/alternative;".
                "boundary = $boundary\r\n\r\n"; 

    $headers .= "This is a MIME encoded message.\r\n\r\n"; 

    $headers .= "--$boundary\r\n".
                "Content-Type: text/plain; charset=ISO-8859-1\r\n".
                "Content-Transfer-Encoding: base64\r\n\r\n"; 
                
    $headers .= chunk_split(base64_encode(strip_tags($HTML))); 

    $headers .= "--$boundary\r\n".
                "Content-Type: text/html; charset=ISO-8859-1\r\n".
                "Content-Transfer-Encoding: base64\r\n\r\n"; 
                
    $headers .= chunk_split(base64_encode($HTML)); 

    mail($to,$subject,"",$headers);
}
I am guessing that perhaps the character encoding is different for each? Or, maybe the header requirements are different for Outlook, Apple, and Gmail?
If you have experienced this, I'd love to know how you've solved this problem.

Thank you

Re: HTML email, good in Gmail but random string in iMail/Out

Posted: Fri Nov 19, 2010 3:47 pm
by s992
Looks like it has something to do with the base64 encoding $HTML. Google for outlook+base64 and imail+base64 and you'll see that there are a good amount of posts about it.