Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-18-2009, 07:57 PM   PM User | #1
SamMonk
New to the CF scene

 
Join Date: Aug 2009
Location: DeLand, FL
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
SamMonk is an unknown quantity at this point
Write Email Attachment To Directory

Hi guys,

Can someone help me finish this script i found. I want to be able to email myself photos and have them put into a directory. This script gets me all the way to the point of isolating the content I want, but how can I write it to a directory on my server. I will be emailing jpeg's from my phone to later display.
PHP Code:
<?php
    
// Read email and process picture attachment according to the subject line.
    
ini_set("display_errors""1");    
    
    
$server "{zimprops.com:143/notls}INBOX";
    
$username "username";
    
$password "password";
        
    
$mbox imap_open($server$username$password);
    echo(
"mbox = " $mbox "<br><br>");
    
    
$headers imap_headers($mbox);
  
    if (
$headers == false) {
        
print_r(imap_errors());
    } else {
        
$j 0;
        foreach (
$headers as $val) {
            
$j += 1;
            
$info imap_headerinfo($mbox,$j);
            
// echo "Recent -> " . $info->Recent;
            
echo "<br><br>-----------------------------";
            echo 
"<br>Unseen -> " $info->Unseen;
            echo 
"<br>Subject -> " $info->subject;
            echo 
"<br>Message ID -> " $info->message_id;
            echo 
"<br>Msgno -> " $info->Msgno;
            
            
$structure imap_fetchstructure($mbox$info->Msgno);
           
            
$attachments = array();
            
            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(
                            
$mbox$info->Msgno$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']);
                        }
                    echo 
"<br>" $attachments[$i]['filename'];
                    echo 
"<br>" $attachments[$i]['attachment'];
                    }
                }
            }
                    
        }
    }
    
imap_close($mbox);
?>
I found this on another forum and I think it comes very close to doing what I want to do. It seems to just be missing the final part.

Thank you,
-Sam
SamMonk is offline   Reply With Quote
Old 09-20-2009, 05:19 AM   PM User | #2
bcarl314
Mega-ultimate member


 
Join Date: Jun 2002
Location: Winona, MN - The land of 10,000 lakes
Posts: 1,855
Thanks: 1
Thanked 45 Times in 42 Posts
bcarl314 will become famous soon enough
I've used this with much success in several projects:

http://www.phpclasses.org/browse/package/3324.html

Might be worth checking out.
bcarl314 is offline   Reply With Quote
Reply

Bookmarks

Tags
email to server, imap, php imap

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:37 PM.


Advertisement
Log in to turn off these ads.