views:

363

answers:

2

sending an email:

From: <...>
X-Mailer: SnowBoss
Reply-To: <...>
X-Priority: 3 (Normal)
Message-ID: <[email protected]>
To: <...>
Subject: =?UTF-8?B?0JzQntCZIFNVQkpFQ1Q=?=
MIME-Version: 1.0
Content-Type: multipart/alternative; boundary="----------A4D921C2D10D7DB"

This is a multi-part message in MIME format.

----------A4D921C2D10D7DB
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit

MY TEXT
----------A4D921C2D10D7DB
Content-Type: text/html;
charset=utf-8
Content-Transfer-Encoding: 8bit

<html><b>BOLD</b></html>
----------A4D921C2D10D7DB
.

<250 Data received OK. //server response

and it comes with empty body. This only happens with multipart/mixed content (tried multipart/alternative - same story)

+1  A: 

I guess you may have boundary set wrong.

The boundary should look like

Content-Type: multipart/alternative; boundary="--------A4D921C2D10D7DB"

meaning - contain two less '-' characters. See the source of any email.

The mail ending boundary - on the other hand - should probably look like

----------A4D921C2D10D7DB--

(again, see the source of any mail message. Or read the RFC, of course :)).

I encourage you to use exisitng mailer classes, like Swift Mailer or PHPMailer. Why reinvent the wheel?

Tomasz Struczyński
afaik boundary doesnt matter anything. anyway, i tried to change - it didn't help
joox
+1  A: 

As Tomasz mentioned, the line where you are using the boundary, you must have two hyphen at the beginning of your boundary separarator. Check the following:

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

This is a message with multiple parts in MIME format.
--frontier
Content-Type: text/plain

This is the body of the message.
--frontier
Content-Type: application/octet-stream
Content-Transfer-Encoding: base64

PGh0bWw+CiAgPGhlYWQ+CiAgPC9oZWFkPgogIDxib2R5PgogICAgPHA+VGhpcyBpcyB0aGUg
Ym9keSBvZiB0aGUgbWVzc2FnZS48L3A+CiAgPC9ib2R5Pgo8L2h0bWw+Cg==
--frontier--

Also notice that at the last boundary, you have to put another two hyphens to indicate that it's the end.

Example taken from Wikipedia, see here.

phpfour
Yes, that's it. Leading and trailing hyphens. THX guys
joox