Re: problem sending attachement with the mail() function [message #178985] |
Fri, 31 August 2012 19:33 |
Eli the Bearded
Messages: 22 Registered: April 2011
Karma:
|
Junior Member |
|
|
In comp.lang.php, anomit <anomit(dot)ghosh(at)gmail(dot)com> wrote:
> I'm going wrong with the message boundaries but some help would be
> appreciated
>
> $random_hash = md5(date('r', time()));
> $subject = "your free pdf is here";
> $headers = "From: no-reply(at)my-domain(dot)com\r\nReply-To: no-
> reply(at)my-domain(dot)com";
> $headers .= "\r\nContent-type: multipart/mixed; boundary=
> \"mailer-boundary-".$random_hash."\"";
^ ^
Note use of double quotes. Very important. MIME, unlike HTML, does not
allow you to switch between single and double quotes in headers.
You are also missing the required "MIME-Version: 1.0" header.
> $attachment =
> chunk_split(base64_encode(file_get_contents('file.pdf')));
> //the body of the message with the message boundaries and
> attachment as multipart mime
> $output = "
> --mailer-boundary-$random_hash
> Content-Type: multipart/alternative; boundary='mailer-alt-
> $random_hash'
Here you not using double quotes, you are using single quotes.
> Content-Type: text/plain; charset='iso-8859-1'
And again. Also it looks like you are missing the blank line between
the multipart/mixed section's headers and the enclosed
multipart/alternative boundary.
MIME is complicated, different from HTML, and flexible in different
ways than HTML. Unless you know those details, and have a good reason
to roll your own, you are probably better off using a pre-built library.
Elijah
------
has written MIME parsers
|
|
|