RE: [PHP] Attachment problem with web based mail
| From: | Grant Walters | Date: | Wed, 21 Mar 2001 11:20:01 +0000 |
| Subject: | RE: [PHP] Attachment problem with web based mail | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-44924@lists.php.net to get a copy of this message | ||
> We hired a developer about a year ago to develop a
> web based email system for us in php. The developer
> is no longer around, so I am having to pick up
> the development on the project...When clicking
> on the attachment link of an email in Internet
> Explorer 5.5 in Windows 98, I get the save as dialog
> and when I select ok, it tries to save the html
> page. If I right click and do save target as, it
> gets the correct file. This all works correctly in
> IE 5.0 and Netscape 4.76, and what's weird is that
> it even works as expected in IE 5.5 running on Win2k.
> Can anyone offer any suggestions? I'll be glad to send
> any code snipplets, or info if anyone can clue me in...
>
> Jack Davis
> Network Admin
> Bootheel Internet Services
I built this a few months ago and it seems to work for most things I have
tried. It is supposed to handle text email clients and MIME clients as
well.
The site variable is a class variable that contains all sorts of stuff.
var $mail_from = "webmaster@walters.co.nz";
var $mail_reply_to = "webmaster@walters.co.nz";
function
mail_it($subject,$mail_message,$mail_to="Grant.Walters@walters.co.nz",$mail_
attachment="",$from="",$reply_to="") {
global $site;
if ($from) { $mail_from="From:$from"; } else
$mail_from="From:".$site->mail_from; }
if ($reply_to) { $mail_reply_to="Reply-To:$reply_to"; } else
$mail_reply_to="Reply-To:".$site->mail_reply_to; }
$rand=md5(rand());
$boundary="----=_NextPart_000_$rand";
$boundary2="----=_NextPart_001_$rand";
$mail_headers = "$mail_from\n$mail_reply_to\n";
$mail_headers .= "Content-Type: multipart/mixed;\n
boundary=\"$boundary\"";
$mail_headers .= "\nX-Priority: 3 (Normal)\nX-Mailer: Walters And
Associates WCDS, Build 1.01\nImportance: Normal";
$mail_body = "";
$mail_body .= " This message is in MIME format. The first part
should";
$mail_body .= "be readable text,\n while the remaining parts are";
$mail_body .= "likely unreadable without MIME-aware tools.\n Send
mail";
$mail_body .= "to webmaster@walters.co.nz for more information.\n";
$mail_body .= "\n";
$mail_body .= "--".$boundary;
$mail_body .= "\n";
$mail_body .= "Content-Type: multipart/alternative;\n
boundary=\"$boundary2\"\n";
$mail_body .= "\n";
$mail_body .= "\n";
$mail_body .= "--".$boundary2."\n";
$mail_body .= "Content-Type: text/plain;\n
charset=\"iso-8859-1\"\n";
$mail_body .= "Content-Transfer-Encoding: 7bit\n";
$mail_body .= "\n";
$mail_body .= strip_tags($mail_message)."\n";
$mail_body .= "\n";
$mail_body .= "\n";
$mail_body .= "--".$boundary2."\n";
$mail_body .= "Content-Type: text/html;\n
charset=\"iso-8859-1\"\n";
$mail_body .= "Content-Transfer-Encoding: quoted-printable\n";
$mail_body .= "\n";
$mail_body .= "$mail_message\n";
$mail_body .= "\n";
$mail_body .= "--".$boundary2."--\n";
$mail_body .= "\n";
if ($mail_attachment<>"") {
$content = get_page($mail_attachment);
if ($content) {
$mail_body .= "--".$boundary."\n";
$mail_body .= "Content-Type: application/octet-stream\n";
$mail_body .= "
name=\"".basename($mail_attachment)."\"\n";
$mail_body .= "Content-Transfer-Encoding: base64\n";
$mail_body .= "Content-Description: \"Mail Attachment\"\n";
$mail_body .= "Content-Disposition: attachment;\n";
$mail_body .= "
filename=\"".basename($mail_attachment)."\"\n";
$mail_body .= "\n";
$mail_body .= base64_encode($content)."\n\n";
}
}
$mail_body .= "--".$boundary."--\n";
if (mail($mail_to,"$subject",$mail_body,$mail_headers)) {
logger(1,"Mail Success","$subject To $mail_to",$mail_message);
return TRUE;
} else {
logger(9,"Mail Failure",$mail_to,$mail_body);
return FALSE;
}
}
Regards
Grant Walters
Brainbench 'Most Valuable Professional' for Unix Admin
Walters & Associates, P O Box 13-043 Johnsonville, Wellington, NEW ZEALAND
Telephone: +64 4 4765175, CellPhone 025488265, ICQ# 23511989