Re: Attachment problem with web based mail - CODE SAMPLE

From: Date: Wed, 21 Mar 2001 22:05:53 +0000
Subject: Re: Attachment problem with web based mail - CODE SAMPLE
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-45006@lists.php.net to get a copy of this message
if you want to change the behaviour of IE or NN with save, then you have to change header of the page you are sending with header comand -almir ""Grant Walters"" <Grant.Walters@walters.co.nz> schrieb im Newsbeitrag news:001101c0b1f8$d7c52080$3d9b60cb@walters.co.nz... > > 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 to handle mail merges with a fixed defied > attachment and it seems to work for most email readers I have tried. It is > supposed to handle text email clients and MIME clients as well as per the > RFC's (It was templated from an outgoing email attachment from Microsoft > Outlook so it will probably screw something up somewhere). > > The site variable is a class variable from an included file that contains > all sorts of default stuff. > class SITE { > var $mail_from = "webmaster@walters.co.nz"; > var $mail_reply_to = "webmaster@walters.co.nz"; > } // END SITE CLASS > > The get page function > function get_page($page_name="") { > $return=""; > if (file_exists($page_name)) > > $fp = fopen("$page_name","r"); > $return .= fread($fp, filesize($page_name)); > fclose($fp); > } > return $return; > } > > The logger function is just a thing thats adds a record to a mysql table to > record the event for later use by my contact management/list procesing > system. > > 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; > } > } > > > Hope this Helps. > > 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 > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net >

« previous php.general (#45006) next »