SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Evangelist hessodreamy's Avatar
    Join Date
    Apr 2005
    Location
    uk
    Posts
    528
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    gibberish results from emails

    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:
    $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:
    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

  2. #2
    Sell crazy someplace else markl999's Avatar
    Join Date
    Aug 2003
    Location
    Manchester, UK
    Posts
    4,007
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    My guess would be your new server is using qmail and it's not happy about the \r\n 's.

    Try using just \n instead.

  3. #3
    SitePoint Evangelist hessodreamy's Avatar
    Join Date
    Apr 2005
    Location
    uk
    Posts
    528
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Spot on. That's the ticket.
    All sorted now. Will have to go and tell of the server 'experts' for not knowing.
    Thanks a lot.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •