gibberish results from emails

the mail() function

Moderators: egami, macek, gesf

Post Reply
New php-forum User
New php-forum User
Posts: 23
Joined: Thu May 26, 2005 1:58 am

Tue Aug 23, 2005 1:00 am

We've got a script that sends emails as html with images and a plaintext alternative.
This worked just fine until we changed server, and now the emails are received by some mail systems as gibberish. By which I guess it's showing the encoded content and not deciphering it.
Out server people say it must be a problem with the code, but they would say that, wouldn't they?

Here's a code snippet

Code: Select all

$plainText = "Some plain text without anything special";
$htmlText = "<p><i>html</i> markup which is fancier</p>";

//add From: header
$headers = "From:\r\n";
//specify MIME version 1.0
$headers .= "MIME-Version: 1.0\r\n";
//unique boundary
$boundary = "unique_bounday_id42";
//tell e-mail client this e-mail contains alternate versions
$headers .= "Content-Type: multipart/alternative" ;
$headers .=   "; boundary = $boundary\r\n\r\n";
//message to people with clients who don't
//understand MIME
$headers .= "This is a MIME encoded message.\r\n\r\n";

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

//HTML version of message
$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($htmlText));
$headers .= $htmlText;
//send message
mail($sendAddress, "Some random title", "", $headers) ;

The mail looks ok on hotmail, but rubbish in outlook and gmail. Here's what it does:

Code: Select all

Content-Type: multipart/alternative; boundary = unique_bounday_id42

This is a MIME encoded message.


Content-Type: text/plain; charset=ISO-8859-1

Content-Transfer-Encoding: base64






and so on until it gets to the html content.

Does the content HAVE to be encoded. I've been getting some pretty unpredictable result if i take out the encoding.

Is there something wrong with the code? or is there smething I can go back to the server people with?


New php-forum User
New php-forum User
Posts: 23
Joined: Thu May 26, 2005 1:58 am

Tue Aug 23, 2005 2:05 am

problem solved. Turned out to be an issue with qmail not liking the \r in the mail.
Took them out and all was sorted.

Post Reply