gmail doesn't like multipart/alternative MIME type?
May 29, 2008 9:30 AM   Subscribe

Does gmail not like the multipart/alternative MIME type?

I'm trying to use php's mail() function to send a multipart/alternative email out to some users. As far as I can tell, I've got the headers and body text right, but when I test it on myself the mail appears blank in the gmail client. Thunderbird (set up to check the same gmail account) seems to like it ok, displaying the html section without issue. What gives?

Here's an example message (actually generated, but with names/content replaced) for your perusal:
From: someone@somewhere.net
MIME-Version: 1.0
Content-Type: multipart/alternative; boundary="bufu8040bufu8040"


--bufu8040bufu8040
Content-Type: text/plain; charset="iso-8859-1"

text version of message

--bufu8040bufu8040
Content-Type: text/html; charset="iso-8859-1"

html version of message

--bufu8040bufu8040
posted by invitapriore to Computers & Internet (8 answers total)
 
Hmm, two questions:

Is the original preserved, if you go look at it, outside the rendering?

Suppose you insert text before the first demarcation, "this is outside the MIME tree, and should not be displayed." What does that do?
posted by cmiller at 9:48 AM on May 29, 2008


Response by poster: Thunderbird allows the option to view the message as HTML or as plain text, and both of the sections show up properly when their respective choice is selected, so it would seem that the body is preserved.

Inserting text before the first boundary instance makes no difference, as expected.

Thanks for the troubleshooting thus far.
posted by invitapriore at 10:01 AM on May 29, 2008


Response by poster: Ah, I found the view source. It is indeed preserved.
posted by invitapriore at 10:04 AM on May 29, 2008


Gmail definitely does support multipart emails, so their must be something about yours specifically that it doesn't like. How many newlines are there after the first Content-Type line and before the boundary (it looks like 2 in your post...), it should just be one, and a little bell is ringing in my head about that having caused me problems in the past.

Using something like Zend_Mail or ezMail will make it a lot easier, generating such emails by hand isn't a lot of fun.
posted by gregjones at 10:06 AM on May 29, 2008


Best answer: The final delimiter in a multipart message should have a double-dash at the end of the line as well as at the beginning. (see, ummmm, rfc2046 section 5.1.1, about midway through). I don't know if that's what's making gmail unhappy, though.
posted by hattifattener at 10:27 AM on May 29, 2008


(curses! slowed by the desire to look up an rfc reference! :) )
posted by hattifattener at 10:28 AM on May 29, 2008


Consider letting PEAR's Mail_Mime package handle all the MIME details for you.
posted by zsazsa at 10:57 AM on May 29, 2008


Response by poster: Those last two dashes were it. Curse incomplete guides on the internet!

Thanks, hades and hattifattener.
posted by invitapriore at 11:46 AM on May 29, 2008


« Older I need a translation of this small Japanese...   |   Grief is itself a medicine. - Cowper Newer »
This thread is closed to new comments.