2

I have a multipart/alternative email that works perfectly on Gmail, Yahoo, and any others I've tried... besides Hotmail (and anything Microsoft I presume.)

The email just appears as raw text on Hotmail.

No matter the amount of times I slam my head against the wall and shout swearwords towards Microsoft which has become a daily activity, I cannot figure out why it doesn't work. Can you?

Here is the email if you want to try it yourself:

Headers:

MIME-Version: 1.0
Content-Type: multipart/alternative;
     boundary="----=_Part_18243133_1346573420.1408991447668"

Body:

------=_Part_18243133_1346573420.1408991447668
Content-Type: text/plain; charset=UTF-8

Hello world.


------=_Part_18243133_1346573420.1408991447668
Content-Type: text/html; charset=UTF-8

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    </head>
    <body>

<p style="margin-top:50px;font-size:9px;">Hello world</p>

</body></html>


------=_Part_18243133_1346573420.1408991447668--

Here is the full code if you want to test it on your server, either use phpmail or wp_mail() that I'm using.

Update: Here is a source of received message to hotmail.

Henrik Petterson
  • 6,862
  • 20
  • 71
  • 155

2 Answers2

2

Probably it is copy-paste to pastbin bug, but your eml contains a space in delimiter line. See here:

--====f230673f9d7c359a81ffebccb88e5d61==
Content-Type: multipart=...<CR><LN>
<SPACE><CR><LN>
^^^^^^^
--====1fdbf23c3658d752511a8dbe74788e30==

If it is not a copy-paste bug than hotmail just can not recognize end of mime entity header.

lazyden
  • 456
  • 5
  • 10
1

What you have looks look to be compliant with RFC2046, so it should work with all MUA's (including Hotmail). But having said that, the way this message is structured is somewhat unusual, and it could be that Hotmail just isn't capable of handing such a message properly, even though it is within spec as far as RFC is concerned.

The more common way of structuring a message containing both a plain text body and an HTML body is to specify multipart/mixed in the headers, then create a multipart/alternative section which encompasses both the plain text body part and the HTML body part, using 'subboundaries' (for lack of a better term) to separate the two body parts. See below:

Message Headers

MIME-Version: 1.0
Content-Type: multipart/mixed; 
boundary="====f230673f9d7c359a81ffebccb88e5d61=="

Message Body

--====f230673f9d7c359a81ffebccb88e5d61==
Content-Type: multipart/alternative;
boundary="====1fdbf23c3658d752511a8dbe74788e30=="

--====1fdbf23c3658d752511a8dbe74788e30==
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit

Hello world.

--====1fdbf23c3658d752511a8dbe74788e30==
Content-Type: text/html; charset="us-ascii"
Content-Transfer-Encoding: 7bit

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>

<p style="margin-top:50px;font-size:9px;">Hello world</p>

</body></html>

--====1fdbf23c3658d752511a8dbe74788e30==--

--====f230673f9d7c359a81ffebccb88e5d61==--
mti2935
  • 11,465
  • 3
  • 29
  • 33
  • Thank you for the response. Used the *edited* code suggested by you but hotmail still generated it as raw text. Could you kindly try it yourself to check if it is working for you? – Henrik Petterson Feb 24 '15 at 17:24
  • Also, I just tried sending this to Gmail and it appeared as some type of file download. I suspect there is an issue somewhere in your code example? – Henrik Petterson Feb 24 '15 at 17:32
  • I think it's because of the text wrapping and line breaks caused by copying and pasting this. I copied the correct source to pastebin at http://pastebin.com/skk915H3. I was able to send what I posted to pastebin as-is using /usr/sbin/sendmail, and it rendered correctly in Thunderbird and gmail (although I don't have a Hotmail account to test with). – mti2935 Feb 24 '15 at 20:46
  • I tested the code in pastebin and it worked fine on Gmail but had the exact same problem as my code when emailing to hotmail. Here is a screen of how it looks: http://i.imgur.com/zcZOHa1.png – Henrik Petterson Feb 28 '15 at 15:06
  • What happens if you get rid of the line ` ` and replace `` with just `` ? – mti2935 Feb 28 '15 at 15:32
  • Also, try putting ` – mti2935 Feb 28 '15 at 15:51
  • Can you view the full source of the message received in Hotmail, and post it to pastebin? – mti2935 Feb 28 '15 at 18:18
  • By any chance, when you view the full source in Hotmail, is there a blank line separating `MIME-Version: 1.0` from the other headers above? – mti2935 Mar 01 '15 at 03:10
  • Not from what I can see, please see full source of message here: http://pastebin.com/3YbYvrPi (note that I removed some user/domain info but that should not be relevant to the issue) – Henrik Petterson Mar 01 '15 at 14:56
  • Looking at the headers of what you posted, I see the `MIME-Version` header line and the `Content-Type` header line from what I posted previously on pastebin, but then immediately after that I see another `MIME-Version` header line and `Content-Type` header line. The second `Content-Type` header line is different than the first one, and it lacks the boundary definition. I suspect that this is what is causing the problem. I see that you are using PHPmailer, and I suspect that PHP mailer is probably adding these additional headers. – mti2935 Mar 01 '15 at 16:00
  • If you are constructing the source of the message from scratch, then is there any reason why you need to use PHP mailer, as opposed to simply sending the message from the local mailer (e.g. /usr/sbin/sendmail)? – mti2935 Mar 01 '15 at 16:02
  • Or, conversely, is there a reason that you are trying to construct the source of the message from scratch, as opposed to using PHP mailer to construct the message? I guess I don't quite understand the full scope of what you are doing with regard to construction and delivery of these messages. – mti2935 Mar 01 '15 at 16:37
  • While this did not directly solve my problem, it did encourage me to locate the cause of the issue which is why I am giving it a bounty. Looks like it was a bug in the WordPress core files, see this thread: https://wordpress.org/support/topic/using-wp_mail-with-php-generated-attachments – Henrik Petterson Mar 08 '15 at 16:02