Jump to content


Photo

Extract attachments from email


  • Please log in to reply
5 replies to this topic

#1 ggurus

ggurus
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 26 June 2006 - 10:08 PM

Hello all,

I am working on a script which has to check incoming email and save any attachments on the webserver along with some basic info, subject line, sent from etc.

This does not have to work realtime, so an admin user for example goes to the script's page and clicks a button and the script will check the mailbox and save the attachments, also storing the other info in a mysql database.

My question is how to extract the attachment from the email. I've been looking around on several forums, hotscripts, experts exchange and google of course, but i can't find anything that explains how to do this. I hope someone here can help me. I'm puzzled [img src=\"style_emoticons/[#EMO_DIR#]/huh.gif\" style=\"vertical-align:middle\" emoid=\":huh:\" border=\"0\" alt=\"huh.gif\" /]

Thanks in advance

#2 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 26 June 2006 - 10:14 PM

Are you trying to get the atachment file name and put that inforamtion in the database.

Then move that atachment to a folder and list the atachments on a page

and then get a link for the admin to be able to look at those atachments.
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#3 ggurus

ggurus
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 26 June 2006 - 11:04 PM

[!--quoteo(post=388235:date=Jun 27 2006, 12:14 AM:name=redarrow)--][div class=\'quotetop\']QUOTE(redarrow @ Jun 27 2006, 12:14 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Are you trying to get the atachment file name and put that inforamtion in the database.
[/quote]

No, I need the actual attachment itself to be saved. So it has to be taken of the mailserver and stored in a folder on the webserver. So say if someone emailed a Word document to script@mysite.com, then when the script is activated by the admin it would check for new email messages and see if there are any attachments. These attachments should then be saved under their original filename in a folder on the webserver.

#4 ggurus

ggurus
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 27 June 2006 - 05:50 AM

Anyone?

#5 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 27 June 2006 - 06:07 AM

when the admin reads an email is it from a php script?

if so post the page that gets that information got an idear here lol......

If the email is being read via a php script then we can add a button to
that script to update the database and then copy the file to another diretory
then let the admin read that email and attchment via another page.

This is all guess work ok but an idear ok.

link from the reading email script.
<a href="http://new_page.php?&cmd=$attachment_name">Save Email</a>

$attachment_name will be the varable set by the email reading script.
<?php

if(!$_GET['cmd']=='$attachment_name') {

$query="insert into database values('$attachment_name')";
$result=mysql_query($query);

$attachment_name;
$newfile = 'attachment_folder/$attachment_name';

if (!copy($attachment_name, $newfile)) {
   echo "failed to copy $file...\n";
}
 }

?> 

I hope this helps a little bit i now the code nearly there lol....
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#6 ggurus

ggurus
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 27 June 2006 - 06:48 AM

Thanks for the help so far, but this isn't exactly what i mean.

The problem lies in that i do not now how to connect to the mailsever using php and then reading out emails from the email box. I would then need some function to read out the contents and find any attachments if they are present and save them to the server.

In the code you put above the attachment is already stored on the server and you're just moving it.

This system is meant to function as a very simple way for people to upate a knowledge base. People just send an email to kb@site.com When the admin goes online and visits the script he would have to click a "check for new email" button, similiar as the way outlook works. Then the script needs to check for mail and store attachments on the webserver.
Now the attachments are saved and added to the db along with some simple info the admin can see a list of new attachments and get's the choice wheter or not to add them to the kb.

All I need to know is how to connect to a mailserver using php and get the mail data from it, including any attachments.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users