Kittsil Kittsil - 7 months ago 27
PHP Question

Content stripped from email on php mail()

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.

Answer

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:

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--