Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Aug 2009
    Location
    DeLand, FL
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    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

  • #2
    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
    I've used this with much success in several projects:

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

    Might be worth checking out.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •