gibberish results from emails

the mail() function

Moderators: macek, egami, gesf

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

gibberish results from emails

Post by hessodreamy » 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: my_email@my_domain.com\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.



--unique_bounday_id42

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

Content-Transfer-Encoding: base64



VGhhbmsgeW91IGZvciB5b3VyIG9yZGVyDQoNCg0KDQpZb3VyIHB1cmNoYXNlIG9yZGVyIG51bWJl

cnMgYXJlLCAgICANCg0KVGhhbmsgeW91IGZvciBwbGFjaW5nIHlvdXIgb3JkZXIgd2l0aCBIeWdp

ZW5lIFN1cHBsaWVzIERpcmVjdCBMaW1pdGVkLg0KDQpZb3VyIG9yZGVyIHNob3VsZCBiZSB3aXRo

IHlvdSB3aXRoaW4gdGhlIHRpbWUgc3RhdGVkIG9ubGluZS4NCg0KSWYgeW91IGhhdmUgbm90IHJl

Y2VpdmVkIHlvdXIgb3JkZXIgd2l0aGluIHRoZSB0aW1lIHN0YXRlZCBvbmxpbmUsIHBsZWFzZSBj


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?

Cheers

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

Post by hessodreamy » 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

Who is online

Users browsing this forum: No registered users and 1 guest