0

I have an email that I am trying to send (the entire email is in the headers). Actually, the email is sending. But when it gets to the destination, the content has been removed. If I send the exact same email, built by the same code from a different server, everything works great just great.

When I print it out using nl2br(htmlspecialchars($headers, ENT_QUOTES)), this is what I get:

From: kittsil@example.com
Reply-to: kittsil@example.com
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="cccf6094979eaede770a2a2e88fc83e9"
Content-Transfer-Encoding: 7bit
This is a MIME encoded message.
--cccf6094979eaede770a2a2e88fc83e9
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: 8bit
You are not being awesome....
--cccf6094979eaede770a2a2e88fc83e9--

When the email is delivered, the body is empty, and when I look at it in Gmail's "show original," it looks the same, but the content is not there.

I am using postfix and OpenDKIM, but I have disabled each of them, and even switched back to sendmail, and none of those emails have bodies. I'm ripping my hair out about this.

Kittsil
  • 2,349
  • 13
  • 22
  • Have you checked your mail logs for postfix or sendmail? Anything interesting in there? – Jason Apr 29 '16 at 12:24
  • You are missing blank lines in your mail body. See the [example here](https://www.w3.org/Protocols/rfc1341/7_2_Multipart.html): "Each part starts with an encapsulation boundary, and then contains a body part consisting of header area, **a blank line**, and a body area." – Gerald Schneider Apr 29 '16 at 12:25
  • @Jason I could not find anything relevant; just connection information with Google's mail servers. – Kittsil Apr 29 '16 at 12:34
  • @GeraldSchneider You are almost definitely right. However, PHP mail() no longers not allows blank lines in the headers (http://stackoverflow.com/questions/30887610/error-with-php-mail-multiple-or-malformed-newlines-found-in-additional-header). Do you have any suggestions? – Kittsil Apr 29 '16 at 12:37
  • Well, then you'll have to use the good old content for it. – Gerald Schneider Apr 29 '16 at 12:38

1 Answers1

1

You are missing blank lines in your mail body.

Quote from the RFC:

Each part starts with an encapsulation boundary, and then contains a body part consisting of header area, a blank line, and a body area.

(Emphasis mine)

Add the proper blank lines and it works:

Header:

From: kittsil@example.com
Reply-to: kittsil@example.com
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="cccf6094979eaede770a2a2e88fc83e9"
Content-Transfer-Encoding: 7bit

Body:

This is a MIME encoded message.

--cccf6094979eaede770a2a2e88fc83e9
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: 8bit

You are not being awesome....
--cccf6094979eaede770a2a2e88fc83e9--
Gerald Schneider
  • 17,416
  • 9
  • 60
  • 78
  • This was it. That was a minified example; our library was (over a year ago) adapted to handle attachments based off of this answer: http://stackoverflow.com/a/12313090. I have changed it to break out the header and body, and it works correctly. Thanks! – Kittsil Apr 29 '16 at 12:46