Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6789469
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:36:29+00:00 2026-05-26T17:36:29+00:00

How to fetch attachments in an email? code $structure = imap_fetchstructure($this->stream, $this->msgno); //print_r($structure); if(isset($structure->parts)){

  • 0

How to fetch attachments in an email?

code

$structure = imap_fetchstructure($this->stream, $this->msgno);
//print_r($structure);
if(isset($structure->parts)){
    foreach($structure->parts as $section => $part){
        if(isset($part->disposition)){
            if(strtolower($part->disposition) == 'attachment'){
                echo 'section = '.$section."\n";
                $body = imap_fetchbody($this->stream, $this->msgno, $section);
                
                $finfo = new finfo(FILEINFO_MIME);
                echo $finfo->buffer($body) . "\n";
                
                $file = Init::$dynamic['data_path'].$this->msgno.'_'.$part->dparameters[0]->value;
                
                imap_savebody($this->stream, $file, $this->msgno, $section);
                
                echo $finfo->file($file) . "\n";
                
                //print_r($body);
            }
        }
    }
}

the returned attachments isn’t even near the correct file size and the returned data looks something like this

ZHUga2VuZGVyIHZlbCBpa2tlIG5vZ2VuIHNvbSBlciB2ZWQgYXQgc3RhcnRlIGVnZW4gdmly
a3NvbWhlZCBlbGxlciBzb20gbGlnZSBlciBzdGFydGV0IG9wPyA6KQ0KDQpmb3JkaSBqZWcg
bmV0b3AgZXIgYmxldmV0IGbmcmRpZyBtZWQgYXQgbGF2ZSBldCD4a29ub21pc3lzdGVtIG1l
ZCBlbiByZXZpc29yIHNvbSBlciB1ZHZpa2xldCBtZWQgc+ZybGlndCBoZW5ibGlrIHDlIGl2
5nJrc+Z0dGVyZSBzb20gb2Z0ZSBpa2tlIGhhciBkZW4gc3RvcmUgaW5kc2lndCBpIPhrb25v
bWkgOik=

Identical files either has the same file size even if they are copies

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T17:36:29+00:00Added an answer on May 26, 2026 at 5:36 pm

    I think your make your code complicate.

    Your problem is you did not get your encode data

    $body = imap_fetchbody($this->stream, $this->msgno, $part);
    //$part=2 (first attachment file)
    //$part=3 (second attachment file) ...
    

    before you can get your real data in that file please take a look at

    $coding = $structure->parts[$part]->encoding;
    if ($coding == 0) {
        $body = imap_7bit($body);
    } elseif ($coding == 1) {
        $body= imap_8bit($body);
    } elseif ($coding == 2) {
        $body = imap_binary($body);
    } elseif ($coding == 3) {
        $body = imap_base64($body);
    } elseif ($coding == 4) {
        $body = imap_qprint($body);
    } elseif ($coding == 5) {
        $body = $body;
    }
    

    so you can try to print this out :

    echo $body;
    

    Note : $section is the part of your files.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I fetch images from a server? I've got this bit of code
how can i fetch the yahoo contacts in asp.net any source code or any
I have this code which export data from GridView to csv. It works with
I'm trying to download attachments from Gmail, using a combination of pieces of code
I am trying to build an automated email that will send attachments based on
This is the code I am using. As suggested I have added the headers
I fetch a JSON array from a web service with touchJSON. Which looks like
I'm trying to fetch some HTML from various blogs and have noticed that different
I'm trying to fetch Wikipedia pages using LWP::Simple , but they're not coming back.
How can I fetch data in a Winforms application or ASP.NET form from a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.