You are producing a malformed message.
Consider using a proper library for generating mail messages, instead of stitching them together from raw strings.
Otherwise, here’s what I notice right away.
- The final multipart boundary must be terminated by an extra
--
, i.e. the last line must be:
--ARandomStringajfas90lsjhntlen89y34oi598--
rather than
--ARandomStringajfas90lsjhntlen89y34oi598
In the attachment parts, you do not have a blank line between the
Content-Disposition
header line and the body.Message lines must not be longer than 998 characters, but your Base64-encoded attachment data, however long, is always on a single line.
As far as I understand PHP, your syntax for
Content-ID
in the attachment parts is wrong, in that it producesContent-ID: \<whatever\>
but should produceContent-ID: <whatever>
Lines must be terminated by CR LF (
\r\n
), but you have LF (\n
).
A good way to debug message problems is to take the actual full generated message source ($message
) and run it through Message Lint. If the above suggestions do not help, please post the generated message source rather than the PHP code.
For the Internet message format, please refer to RFC 5322. For the multipart message syntax, please refer to RFC 2046.