Search code examples
emailmime

Whats wrong with my multipart/alternative Email?


I'm trying to build up my own Email sending class and it seems I have a bug with my MIME. If someone could find the error or tell me about a working MIME Validator I would really appreciate that.

Thanks in advance JD

To: me@mydomain.com
Subject: Test Alternate
X-PHP-Originating-Script: 1000:SendMail.class.php
MIME-Version: 1.0
From: me@mydomain.com
Content-Type: multipart/mixed;
 boundary="MultipartMail53dfa8ade817e"
Message-Id: <20140804153717.EA93E160195@myDevice>
Date: Mon,  4 Aug 2014 17:37:17 +0200 (CEST)
X-RCPT-TO: <me@mydomain.com>
Status:  
X-UIDL: 706801872
X-IMail-ThreadID: c9b40003d631c851

--MultipartMail53dfa8ade817e
Content-Type: multipart/alternative;
 boundary="Alternative53dfa8ade8378"


--Alternative53dfa8ade8378
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

Some Text content


--Alternative53dfa8ade8378
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit


Das ist Text
-- 

Text

*Some more Text*
Text



--Alternative53dfa8ade8378--

--MultipartMail53dfa8ade817e--

Solution

  • There's a few things "wrong" with your email:

    Firstly, you have a non-header in your header:

    To: me@mydomain.com
    *Test Alternate*
    X-PHP-Originating-Script: 1000:SendMail.class.php
    

    (*'s around the broken bit)

    Secondly, (and probably your main issue with Thunderbird) is that your multipart/alternative has the child parts in the wrong order. The way that multipart/alternative is supposed to work is that the last part is supposed to be the form that is closest to what the original author of the message intended for you to see (IOW what he/she saw in their WYSIWYG editor).

    TL;DR

    Put the text/html part last and the text/plain part first within the multipart/alternative.