Jump to content

Recommended Posts

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
Link to comment
https://forums.phpfreaks.com/topic/12963-extract-attachments-from-email/
Share on other sites

[!--quoteo(post=388235:date=Jun 27 2006, 12:14 AM:name=redarrow)--][div class=\'quotetop\']QUOTE(redarrow @ Jun 27 2006, 12:14 AM) [snapback]388235[/snapback][/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.
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.
[code]
<a href="http://new_page.php?&cmd=$attachment_name">Save Email</a>
[/code]

$attachment_name will be the varable set by the email reading script.
[code]
<?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";
}
}

?>
[/code]

I hope this helps a little bit i now the code nearly there lol....
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.
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.