Hi guys! I found this script doing a google search for extracting attachments from emails using php and imap. It seems to be working just fine as far as logging in and I can even extract an attachment from a single email but I need to be able to extract several attachments from more than one email and then save them to my site. Something like this added to the script:
PHP Code:
foreach ($content as $data)
{ file_put_contents($filename, $data); }
I know that's not the correct syntax but hopefully you understabd what I mean. Here's the script below:
// Gets the current email structure (including parts)
// Use var_dump($structure) to check it out
$structure = imap_fetchstructure($mbox, $info->Msgno);
switch ($at['encoding']) {
case '3':
$content = base64_decode($content);
break;
case '4':
$content = quoted_printable_decode($content);
break;
}
}
}
}
// Shutting down
imap_close($mbox);
/**
* Gets all attachments
* Including inline images or such
* @author: Axel de Vignon
* @param $content: the email structure
* @param $part: not to be set, used for recursivity
* @return array(type, encoding, part, filename)
*
*/
function get_attachments($content, $part = null) {
static $results;
// First round, emptying results
if (is_null($part)) {
$results = array();
}
// Gets the current email structure (including parts)
// Use var_dump($structure) to check it out
$structure = imap_fetchstructure($mbox, $info->Msgno);
break;
case '4':
$content = quoted_printable_decode($content);
break;
}
}
}
}
// Shutting down
imap_close($mbox);
/**
* Gets all attachments
* Including inline images or such
* @author: Axel de Vignon
* @param $content: the email structure
* @param $part: not to be set, used for recursivity
* @return array(type, encoding, part, filename)
*
*/
function get_attachments($content, $part = null) {
static $results;
// First round, emptying results
if (is_null($part)) {
$results = array();
}
I finally figured out why I'm getting that error after putting that code inside an if statemant, but I still don't know how to fix it so it works.
Quote:
If called from within a function, the return() statement immediately ends execution of the current function, and returns its argument as the value of the function call. return() will also end the execution of an eval() statement or script file.
Can somebody show me how to fix that script so that it can be put inside an if statement so I can use it with a form. I would greatly appreciate it.