473,385 Members | 1,769 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

getting attachment from the mail using mime type

realin
254 100+
hiya all,

I searched for a script and now i m able to receive the email from the server. Now the issue left is how to i download the attachments(if any) with that email. google led to me a wonderful link and i was able to download class called MimeDecode, which lets me parse headers into different array according to the content type.

Well i get the attachment in the form of array, but the problem is now, how do i store/display it in browser. I know i have set the content-type in headers, but still it is not working can any one help me.

http://pastebin.com/m61e9e752

i have pasted the output of the array on above link..

Cheers !!
Realin !
May 12 '08 #1
4 1956
Atli
5,058 Expert 4TB
Hi.

If you have the mime/type and the data, you could try storing the data in a temp file and call it from another PHP script that uses the correct headers.
May 12 '08 #2
realin
254 100+
Hi.

If you have the mime/type and the data, you could try storing the data in a temp file and call it from another PHP script that uses the correct headers.
this is what i am planning how do i do it,
i m planning to make some cases for different headers like text/plain,image/jpg etc
then how do i store these ??
i mean storing an image can be done using imagefromjpg() function, but is that the right way to do it ??

Thanks for the reply :)
Realin !
May 12 '08 #3
Atli
5,058 Expert 4TB
You could simply use the file_put_contents function to store it in a temporary file and pass the name of that file to your second PHP file.

Something like:
Expand|Select|Wrap|Line Numbers
  1. // Get the file data and mime type
  2. $fileData = "This would be the data from your email array";
  3. $fileMime = "image/jpeg"; // Or whatever
  4.  
  5. // Set file path and create the file name
  6. $filePath = "/path/to/your/tmp/dir/";
  7. $fileName = "temp_file_". microtime(true) .".tmp";
  8.  
  9. // Save file and print link, or error if it fails
  10. if(file_put_contents($filePath . $fileName, $fileData)) {
  11.   echo "Click <a href='readFile.php?fName={$fileName}&mime={$fileMime}'>here</a> to download</a>";
  12. else {
  13.   echo "Failed to save the file! Make sure you have write permission.";
  14. }
  15.  
And then in the readFile.php:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. // Get the values
  3. $filePath = "/path/to/your/tmp/dir/";
  4. $fileName = $_GET['fName'];
  5. $mime = $_GET['mime'];
  6.  
  7. // Make sure the file exists
  8. if(!file_exists($filePath . $fileName)) {
  9.   die("Invalid file name provided");
  10. }
  11.  
  12. // Set headers
  13. header("Content-Type: ". $mime);
  14. header("Content-Length: ".filesize($filename));
  15. header("Content-Disposition: attachment; filename=\"".basename($fileName)."\";" );
  16. header("Content-Transfer-Encoding: binary");
  17.  
  18. // Print file data
  19. readfile($filePath . $fileName);
  20.  
  21. // Delete file, if you want that
  22. unlink($filePath . $fileName);
  23.  
  24. exit();
  25. ?>
  26.  
Thats at least the general idea.
Good luck :)
May 13 '08 #4
realin
254 100+
hiya atil,

gonna try this now..
Well wat should i say.. ummm..
THANKSSSSSSSS :p
Heheheh..

Will surely paste my working code, if it will work
May 13 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: a c s | last post by:
Hi there, my problem is as follows: When emailing a file using PHP 4.0.6, the attachment received is an empty "attachment.txt" file instead of the actual file I attached. Any suggestions why...
2
by: knoak | last post by:
Hi there, I've found a script at these great Google fora. a script to send emails with attachments. The script is below this message, name etc. aren't mine, but from the original post. My...
0
by: Matthew Lenz | last post by:
We've got a couple emails that are sent to an account on a daily basis from a third party vendor we work with. They mime encode the actual data (text/plain) and include it as an attachment (the...
4
by: Reticulated Ember | last post by:
I have the following code that fails with an invalid cast exception: .... System.Web.Mail.MailMessage msg = new System.Web.Mail.MailMessage(); msg.BodyFormat = MailFormat.Html; ...
2
by: Der tolle Emil | last post by:
Hi! I wrote a little function to send emails which works quite well. I already managed to send attachments correctly (also more than 1 per email) but I am not able to send a HTML mail containing...
0
by: sachintandon | last post by:
Hello all, Thanks in advance for your help I have a problem in sending emails, my requirement is to send multipart alternative emails with attachments, I'm able to send text with attachments or...
9
by: deepaks85 | last post by:
Dear Sir, I have created a simple request form which will be mailed to me. Now I want to attach files and send it through that request form. For this I am using the following script: ...
1
by: nukephp | last post by:
Hello Guys would you know about php email with his attachment Working on linux platform................................................... The code as below: mail.php <?php //define the...
1
by: Chitu03 | last post by:
Hi I am already send a mail using Php with some attachement into it. My Problem is the attachement file is in my Database(mysql). I don't know how can i get from database and then add to my mail....
1
by: deepaks85 | last post by:
Dear All, I want to send some data through a form with Multiple attachment in an HTML Format. I have tried it but it is not working for me. I am able to send data without attachment but with the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.