[PHP] attachment problem
Hi all! I'm writing a webmail application in PHP and most basic things are working now. However, I've recently run into a problem concerning mail attachments. This is the situation right now: When the user opens a letter there are links to all attachments. The links looks like this: http://www.lassoweb.nu/webmail/attachment.php/mailbox=INBOXmsguid=218part=2 Mailbox is the mailbox name, msguid is the message number and part corresponds to the part of the letter that is an attachment. When the user clicks the link the attachment data is extracted from the message and displayed in the browser (if possible). This works nice, but here comes the problem. Since the document is named 'attachment.php', that's the name that comes up in the save box whenever the user tries to save the file. Iv'e tried setting the Content-Disposition header to tell the browser what to call the attachment, but to no avail. The browser still insists on calling all attachments 'attachment.php'! I've been trying to figure this out for a couple of days now, but no luck yet. Perhaps someone out there have had the same problem (and solved it)? I'm thankful for any hints /Lars 'lasso' Olsson ([EMAIL PROTECTED]) PS. One solution might be to 'trick' the browser by creating a fake URL (like http://www.lassoweb.nu/webmail/void/bob.gif), but in order for this to work I need to tell Apache to send all requests to the 'void' directory to a single PHP file. Anyone knows how to set this up? DS. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] attachment problem
So you have tried as per the manual: header(Content-Disposition: attachment; filename=downloaded.pdf); I use this all the time without issue.. do you have a shell that you can use to wget -S and see if the correct headers are coming out?? Timothy Hitchens (HiTCHO) Open Platform Consulting e-mail: [EMAIL PROTECTED] -Original Message- From: Lars Olsson [mailto:[EMAIL PROTECTED]] Sent: Monday, 13 January 2003 11:05 PM To: [EMAIL PROTECTED] Subject: [PHP] attachment problem Hi all! I'm writing a webmail application in PHP and most basic things are working now. However, I've recently run into a problem concerning mail attachments. This is the situation right now: When the user opens a letter there are links to all attachments. The links looks like this: http://www.lassoweb.nu/webmail/attachment.php/mailbox=INBOXms guid=218part=2 Mailbox is the mailbox name, msguid is the message number and part corresponds to the part of the letter that is an attachment. When the user clicks the link the attachment data is extracted from the message and displayed in the browser (if possible). This works nice, but here comes the problem. Since the document is named 'attachment.php', that's the name that comes up in the save box whenever the user tries to save the file. Iv'e tried setting the Content-Disposition header to tell the browser what to call the attachment, but to no avail. The browser still insists on calling all attachments 'attachment.php'! I've been trying to figure this out for a couple of days now, but no luck yet. Perhaps someone out there have had the same problem (and solved it)? I'm thankful for any hints /Lars 'lasso' Olsson ([EMAIL PROTECTED]) PS. One solution might be to 'trick' the browser by creating a fake URL (like http://www.lassoweb.nu/webmail/void/bob.gif), but in order for this to work I need to tell Apache to send all requests to the 'void' directory to a single PHP file. Anyone knows how to set this up? DS. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] attachment problem
Yes, I've tried using the Content-Disposition header. It doesn't seem to work...here are the relevant parts of my code: snip // Change Content-Type so that it matches the MIME-type of the part header('Content-Type: ' . $type . '/' . $subtype); // Check if there is a name for the part if (isset($name)) { header('Content-Disposition: inline; filename=' . $name); } else { header('Content-Disposition: inline'); } /snip I've tried printing $type, $subtype and $name and they all contain correct values...still no luck. As per your suggestion I tried using wget -S to check the headers. Here are the results: C:\WINDOWS\Profiles\Lasso\Skrivbordetwget -S --spider http://localhost/webmail/ attachment.php?mailbox=INBOXmsguid=279part=2 --21:59:30-- http://localhost/webmail/attachment.php?mailbox=INBOXmsguid=279p art=2 = `attachment.php@mailbox=INBOXmsguid=279part=2' Resolving localhost... done. Connecting to localhost[127.0.0.1]:80... connected. HTTP request sent, awaiting response... 1 HTTP/1.1 200 OK 2 Date: Mon, 13 Jan 2003 20:59:39 GMT 3 Server: Apache/1.3.27 (Win32) PHP/4.2.3 4 X-Powered-By: PHP/4.2.3 5 Set-Cookie: PHPSESSID=12ab68cb5cd7355b2a63b9007bda0221; path=/ 6 Expires: Thu, 19 Nov 1981 08:52:00 GMT 7 Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 8 Pragma: no-cache 9 Keep-Alive: timeout=15, max=100 10 Connection: Keep-Alive 11 Content-Type: text/html 200 OK I'm VERY confused about line 11! The type (for this particular request) should be image/bmp (Mozillas Page Info tab confirms this). Still, wget claims it is text/html...hm...strange...now what? /Lars Olsson ([EMAIL PROTECTED]) Timothy Hitchens ) wrote: So you have tried as per the manual: header(Content-Disposition: attachment; filename=downloaded.pdf); I use this all the time without issue.. do you have a shell that you can use to wget -S and see if the correct headers are coming out?? Timothy Hitchens (HiTCHO) Open Platform Consulting e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] attachment problem
What happens when you change the inline to attachment?? Also does this page have any errors in it... eg parsing ones that are causing PHP to take over the headers and error out?? Timothy Hitchens (HiTCHO) Open Platform Consulting e-mail: [EMAIL PROTECTED] -Original Message- From: Lars Olsson [mailto:[EMAIL PROTECTED]] Sent: Tuesday, 14 January 2003 7:15 AM To: [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Subject: Re: [PHP] attachment problem Yes, I've tried using the Content-Disposition header. It doesn't seem to work...here are the relevant parts of my code: snip // Change Content-Type so that it matches the MIME-type of the part header('Content-Type: ' . $type . '/' . $subtype); // Check if there is a name for the part if (isset($name)) { header('Content-Disposition: inline; filename=' . $name); } else { header('Content-Disposition: inline'); } /snip I've tried printing $type, $subtype and $name and they all contain correct values...still no luck. As per your suggestion I tried using wget -S to check the headers. Here are the results: C:\WINDOWS\Profiles\Lasso\Skrivbordetwget -S --spider http://localhost/webmail/ attachment.php?mailbox=INBOXmsguid=279part=2 --21:59:30-- http://localhost/webmail/attachment.php?mailbox=INBOXmsguid=279p art=2 = `attachment.php@mailbox=INBOXmsguid=279part=2' Resolving localhost... done. Connecting to localhost[127.0.0.1]:80... connected. HTTP request sent, awaiting response... 1 HTTP/1.1 200 OK 2 Date: Mon, 13 Jan 2003 20:59:39 GMT 3 Server: Apache/1.3.27 (Win32) PHP/4.2.3 4 X-Powered-By: PHP/4.2.3 5 Set-Cookie: PHPSESSID=12ab68cb5cd7355b2a63b9007bda0221; path=/ 6 Expires: Thu, 19 Nov 1981 08:52:00 GMT 7 Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 8 Pragma: no-cache 9 Keep-Alive: timeout=15, max=100 10 Connection: Keep-Alive 11 Content-Type: text/html 200 OK I'm VERY confused about line 11! The type (for this particular request) should be image/bmp (Mozillas Page Info tab confirms this). Still, wget claims it is text/html...hm...strange...now what? /Lars Olsson ([EMAIL PROTECTED]) Timothy Hitchens ) wrote: So you have tried as per the manual: header(Content-Disposition: attachment; filename=downloaded.pdf); I use this all the time without issue.. do you have a shell that you can use to wget -S and see if the correct headers are coming out?? Timothy Hitchens (HiTCHO) Open Platform Consulting e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] attachment problem
It doesn't matter whether I choose 'inline' or 'attachment', browser doesn't seem to care...but at least I found out why wget -S got me text/html instead of image/bmp. I had some session variables that messed things up, but I hacked it a bit and now wget -S is giving me the following headers: C:\WINDOWS\Profiles\Lasso\Skrivbordetwget -S --spider http://localhost/webmail/ attachment.php?mailbox=INBOXmsguid=279part=2 --00:19:19-- http://localhost/webmail/attachment.php?mailbox=INBOXmsguid=279p art=2 = `attachment.php@mailbox=INBOXmsguid=279part=2' Resolving localhost... done. Connecting to localhost[127.0.0.1]:80... connected. HTTP request sent, awaiting response... 1 HTTP/1.1 200 OK 2 Date: Mon, 13 Jan 2003 23:19:27 GMT 3 Server: Apache/1.3.27 (Win32) PHP/4.2.3 4 X-Powered-By: PHP/4.2.3 5 Set-Cookie: PHPSESSID=e4025c8fb31d0de0b04c7aa0e3afc676; path=/ 6 Expires: Thu, 19 Nov 1981 08:52:00 GMT 7 Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 8 Pragma: no-cache 9 Content-Disposition: inline; filename=tomtefan.bmp 10 Keep-Alive: timeout=15, max=100 11 Connection: Keep-Alive 12 Content-Type: image/bmp 200 OK The Content-Type seems ok, and so does the Content-Disposition. Browser still suggests 'attachment.php' whenever I choose File-Save As... Strange happenings indeed... /Lars ([EMAIL PROTECTED]) Timothy Hitchens (HiTCHO) wrote: What happens when you change the inline to attachment?? Also does this page have any errors in it... eg parsing ones that are causing PHP to take over the headers and error out?? Timothy Hitchens (HiTCHO) Open Platform Consulting e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] attachment problem
Well, I'll be damned...don't know why, but suddenly everything seems to work! Guess some little gnome inside my computer finally decided it was time for me to get some sleep... Many thanx for for your help, Timothy! /Lars ([EMAIL PROTECTED]) Lars Olsson wrote: It doesn't matter whether I choose 'inline' or 'attachment', browser doesn't seem to care...but at least I found out why wget -S got me text/html instead of image/bmp. I had some session variables that messed things up, but I hacked it a bit and now wget -S is giving me the following headers: C:\WINDOWS\Profiles\Lasso\Skrivbordetwget -S --spider http://localhost/webmail/ attachment.php?mailbox=INBOXmsguid=279part=2 --00:19:19-- http://localhost/webmail/attachment.php?mailbox=INBOXmsguid=279p art=2 = `attachment.php@mailbox=INBOXmsguid=279part=2' Resolving localhost... done. Connecting to localhost[127.0.0.1]:80... connected. HTTP request sent, awaiting response... 1 HTTP/1.1 200 OK 2 Date: Mon, 13 Jan 2003 23:19:27 GMT 3 Server: Apache/1.3.27 (Win32) PHP/4.2.3 4 X-Powered-By: PHP/4.2.3 5 Set-Cookie: PHPSESSID=e4025c8fb31d0de0b04c7aa0e3afc676; path=/ 6 Expires: Thu, 19 Nov 1981 08:52:00 GMT 7 Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 8 Pragma: no-cache 9 Content-Disposition: inline; filename=tomtefan.bmp 10 Keep-Alive: timeout=15, max=100 11 Connection: Keep-Alive 12 Content-Type: image/bmp 200 OK The Content-Type seems ok, and so does the Content-Disposition. Browser still suggests 'attachment.php' whenever I choose File-Save As... Strange happenings indeed... /Lars ([EMAIL PROTECTED]) Timothy Hitchens (HiTCHO) wrote: What happens when you change the inline to attachment?? Also does this page have any errors in it... eg parsing ones that are causing PHP to take over the headers and error out?? Timothy Hitchens (HiTCHO) Open Platform Consulting e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] attachment problem
Hi Olev: There are several threads on this in the archives. In fact it was discussed just the other day. http://groups.google.com/groups?hl=engroup=php.general Put mime email into the search criteria and that discussion is the third one down. Enjoy, --Dan -- PHP scripts that make your job easier http://www.analysisandsolutions.com/code/ SQL Solution | Layout Solution | Form Solution T H E A N A L Y S I S A N D S O L U T I O N S C O M P A N Y 4015 7 Ave, Brooklyn NY 11232v: 718-854-0335f: 718-854-0409 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] attachment problem
Hello gurus, need some help here please. I have mail php script with out attachment possibilities. How can I add attachment in to this one? ? $MailToAddress = [EMAIL PROTECTED]; $MailSubject = subject; if (!$MailFromAddress) { $MailFromAddress = [EMAIL PROTECTED]; } $Header = header; $Footer = Footer; ? html body bgcolor=#FF font face=Arialcenter The following information has been delivered: /center ? if (!is_array($HTTP_POST_VARS)) return; reset($HTTP_POST_VARS); while(list($key, $val) = each($HTTP_POST_VARS)) { $GLOBALS[$key] = $val; $val=stripslashes($val); echo b$key/b = $valbr; $Message .= $key = $val\n; } if ($Header) { $Message = $Header.\n\n.$Message; } if ($Footer) { $Message .= \n\n.$Footer; } mail( $MailToAddress, $MailSubject, $Message, From: $MailFromAddress); ? / last part I changed like this: mail( $MailToAddress, $MailSubject, $Message, From: $MailFromAddress, $attachment); and there are forms in my html: FORM name=your_file value=200input name=attachment type=file input type=text name=MailFromAddress input type=submit value=Submit / I recieve the mail with all the req. fields, but attachment is not picked up, instead it writes: Attacment=c:\picture.gif So what is wrong?
RE: [PHP] Attachment problem with web based mail
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 = "[EMAIL PROTECTED]"; var $mail_reply_to = "[EMAIL PROTECTED]"; function mail_it($subject,$mail_message,$mail_to="[EMAIL PROTECTED]",$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 [EMAIL PROTECTED] 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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Attachment problem with web based mail - CODE SAMPLE
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"" [EMAIL PROTECTED] schrieb im Newsbeitrag 001101c0b1f8$d7c52080$[EMAIL PROTECTED]">news:001101c0b1f8$d7c52080$[EMAIL PROTECTED]... 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 = "[EMAIL PROTECTED]"; var $mail_reply_to = "[EMAIL PROTECTED]"; } // 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="[EMAIL PROTECTED]",$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 [EMAIL PROTECTED] 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
[PHP] Attachment problem with web based mail
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... Thanks in advance, Jack Davis Network Admin Bootheel Internet Services [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]