A
Anonymous
Guest
I'm trying to teach myself how to MIME encode HTML emails with attachments, and I was hoping some of you wouldn't mind helping me out....
Here is the code I've written so far:
The first couple of HTML lines look OK (in a test email), and then when I get to the first attachment, things get fouled up...instead of seeing the attachment, I see a bunch of code.....
If someone could tell me what I'm doing wrong, I'd appreciate it...
thanks.
__________________
R.J.
http://www.mediamogulsweb.com
Here is the code I've written so far:
Code:
<?
/* attachments */
$attach[0] = "Newsletter/0105e2.gif";
$attach[1] = "Newsletter/0105e3.gif";
$attach[2] = "Newsletter/0105e4.jpg";
$attach[3] = "Newsletter/ACF2D3.jpg";
$attach[4] = "Newsletter/logo3.jpg";
$attach[5] = "Newsletter/logo4.jpg";
$attach[6] = "Newsletter/mainarrow_white.gif";
$attach[7] = "Newsletter/spacer.gif";
for($i=0; $i <= 7; $i++)
{
$fp = fopen($attach[$i],'rb');
$attachment[$i] = fread($fp,filesize($attach[$i]));
//$attachment[$i] = chunk_split(base64_encode($attachment[$i]));
fclose($fp);
}
/* subject */
$subject = "Media Moguls Newsletter";
// Generate a boundary string
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
/* headers */
$headers = "From: Admin<rjaffe@mediamogulsweb.com>\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: multipart/mixed; boundary=\"{$mime_boundary}\"\r\n";
// Add a multipart boundary above the plain message
$body = "This is a multi-part message in MIME format.\r\n";
$body .= "--{$mime_boundary}\r\n";
$body .= "Content-Type: text/html; charset=\"iso-8859-1\"\r\n";
$body .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
/* HTML message */
$body .= '
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML>
.....blah, blah, blah, insert HTML here....
<br>
<span align="center" valign="top"><a href="http://www.mediamogulsweb.com" target="blank"><img src="';
// Add inline file attachment to the message
$body .= "--{$mime_boundary}\r\n";
$body .= "Content-Type: $attach[5]_type;\r\n" .
" name=\"$attach[5]_name\"\r\n";
$body .= "Content-Transfer-Encoding: base64\r\n";
$body .= "Content-Disposition: inline;\r\n" .
" filename=\"$attach[5]_name\"\r\n";
$body .= "$attachment[5]";
$body .= "--{$mime_boundary}\r\n";
$body .= "Content-Type: text/html; charset=\"iso-8859-1\"\r\n";
$body .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
$body .= '
" border="0"></span>
...blah, blah, blah, more HTML....
</BODY>
</HTML>
';
$body .= "--{$mime_boundary}--\r\n\r\n";
/* and now mail it */
mail($mail_to, $subject, $body, $headers);
?>
The first couple of HTML lines look OK (in a test email), and then when I get to the first attachment, things get fouled up...instead of seeing the attachment, I see a bunch of code.....
If someone could tell me what I'm doing wrong, I'd appreciate it...
thanks.
__________________
R.J.
http://www.mediamogulsweb.com