[thelist] PHP4 HTML Email
BT Bigpant
thelist at lists.evolt.org
Mon Feb 4 01:02:01 2002
The format for mail is *really* fussy. Don't use \r\n, just \n. You must
have \n\n after each section. The following illustrates the idea. Line
breaks are for clarity only, remove them to be sure. So, you have the
header, ended with \n\n followed by the body, again ended with \n\n and then
the attachment \n\n. You must finish the email with --$boundary-- Make sure
that $boundary will not appear in $data by using something like md5.
This *should* work, I have stripped it from one of my apps and ammended it
to suit your needs, so apologies for any errors.
$boundary = "B" . md5(time());
$header = "
From: \"$return_email_title\" $return_email\n
Subject: $subject\n
Date: $thedate\n
Message-ID: <1234@abc>$return_email\n
MIME-Version: 1.0\n
Content-Type: multipart/mixed; boundary=\"$boundary\";\n
Content-Transfer-Encoding: 7bit\n
This part of the email should never be seen. If you are reading this,
consider upgrading your e-mail client to a MIME-compatible one.\n
--$boundary\n
Content-Type:text/plain; charset=\"iso-8859-1\"\n
Content-Transfer-Encoding: 7bit\n\n
$email_body\n\n
--$boundary\n
Content-Type: application/octet-stream; name=\"$filename\"\n
Content-Transfer-Encoding: base64\n
Content-Disposition: attachment\n\n
$data\n\n
--$boundary--
";
mail ($recipient, $subject, "", $header);
HTH
Phil Parker
-----Original Message-----
From: thelist-admin@lists.evolt.org
[mailto:thelist-admin@lists.evolt.org]On Behalf Of Peter Atkins
Sent: 31 January 2002 19:39
To: 'thelist@lists.evolt.org'
Subject: [thelist] PHP4 HTML Email
All,
I'm building a tool that takes form input and sends out an html email with a
word doc attached.
It sends the text and html version of the email but I can't open the
attachment. It opens blank.
Anyone have a thought or two about this?
<php snippet>
if ($attachment) {
$fp = fopen($attachment, "rb");
$data = fread($fp, filesize($attachment));
$data = chunk_split(base64_encode($data));
fclose($fp);
// add the MIME data
$str .= "--" . $boundary . "\r\n";
$str .= "Content-Type: application/octet-stream; name=\"" .
$attachment ."\"\r\n";
$str .= "Content-Transfer-Encoding: base64\r\n";
$str .= "Content-Disposition: attachment; filename=\"" . $attachment
."\"\r\n\r\n";
$str .= $data . "\r\n";
}
</php snippet>
thanks,
-p
--
For unsubscribe and other options, including
the Tip Harvester and archive of thelist go to:
http://lists.evolt.org Workers of the Web, evolt !