PHP Multipart Email Getting Cut Off

November 12th, 2010 - Posted by Steve Marks to PHP, Web Development.

By sending multipart emails we can send two versions of the same email at the same time; One sexy HTML version containing all the bells and whistles for modern email clients, and a fallback plain text version for older email clients or users who have HTML formatting disabled.

Without the use of a class or framework I’ve always found sending multipart emails with the PHP mail() function a bit fiddly and hard to debug if something is wrong. This was confirmed earlier today when a script I was writing to perform this function resulted in emails having the first section cut off.

The Solution

After nearly going bald through pulling my hair out over this (that’s a lot of hair!) it turns out the issue was caused by using a mixture of both ‘\n’ and ‘\r\n’ as new line characters in the email headers. Changing them all to read ‘\r\n’ resolved the issue right away and the full email was now coming through.

This entry was posted on Friday, November 12th, 2010 at 7:56 pm by +Steve Marks and is filed under PHP, Web Development. You can follow any responses to this entry through the RSS 2.0 feed.

Fear not, we won't publish this

Comments (1)
  1. Mine was the other way around. I got issue with “\r\n” but when I changed it to “\n”, works like a charm.. :)

    Thanks for the tip anyway.. :) God Bless!