hi there

thanks for all your assistance,

have managed to use IMAP to check the inbox and find the attachments,

however i am finding difficulty in saving the attachments to a file folder
on the server,

any advice?

i am using this function to extract attachments from the emails:

function extract_attachments($connection, $message_number) {

    $attachments = array();
    $structure = imap_fetchstructure($connection, $message_number);

    if(isset($structure->parts) && count($structure->parts)) {

        for($i = 0; $i < count($structure->parts); $i++) {

            $attachments[$i] = array(
                'is_attachment' => false,
                'filename' => '',
                'name' => '',
                'attachment' => ''
            );

            if($structure->parts[$i]->ifdparameters) {
                foreach($structure->parts[$i]->dparameters as $object) {
                    if(strtolower($object->attribute) == 'filename') {
                        $attachments[$i]['is_attachment'] = true;
                        $attachments[$i]['filename'] = $object->value;
                    }
                }
            }

            if($structure->parts[$i]->ifparameters) {
                foreach($structure->parts[$i]->parameters as $object) {
                    if(strtolower($object->attribute) == 'name') {
                        $attachments[$i]['is_attachment'] = true;
                        $attachments[$i]['name'] = $object->value;
                    }
                }
            }

            if($attachments[$i]['is_attachment']) {
                $attachments[$i]['attachment'] = imap_fetchbody($connection,
$message_number, $i+1);
                if($structure->parts[$i]->encoding == 3) { // 3 = BASE64
                    $attachments[$i]['attachment'] =
base64_decode($attachments[$i]['attachment']);
                }
                elseif($structure->parts[$i]->encoding == 4) { // 4 =
QUOTED-PRINTABLE
                    $attachments[$i]['attachment'] =
quoted_printable_decode($attachments[$i]['attachment']);
                }
            }

        }

    }

    return $attachments;

}


On Tue, Oct 26, 2010 at 11:57 AM, Brendan Brink
<[email protected]>wrote:

> Hi there,
>
> Wanting to accomplish the following:
>
> 1. Setup a special email address at my domain.
> 2. Using PHP, poll the email address inbox for unread emails every 5
> minutes or so (using CRON job)
> 3. If there is an email extract the attachment on the email and save
> as a file on the server.
> 4. Mark the email as read.
>
> Anyone had any experience or has a good tutorial on how to do this
> correctly?
>
> Cheers
> Brendan.
>



-- 
Kind Regards,

Brendan Brink

SMS Marketing Consultant | Manager
Sell2Cell Ltd.

021 0246 1646 | [email protected] | www.sell2cell.co.nz




  We provide customized, cost-effective SMS & Web Solutions
  Need a website? Need to integrate text-messaging into your business
  or website? Contact us today for a free no-obligation quote!

  VISIT OUR ASSOCIATED WEBSITES:   textvouchers.com | textguru.co.nz

WARNING This email contains information which is CONFIDENTIAL and may be
subject to LEGAL PRIVILEGE. If you are not the intended recipient, you must
not peruse, use, disseminate, distribute or copy the email or attachments.
If you have received this in error, please notify us immediately by return
email, facsimile, or telephone (call us collect).

-- 
NZ PHP Users Group: http://groups.google.com/group/nzphpug
To post, send email to [email protected]
To unsubscribe, send email to
[email protected]

Reply via email to