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

  • Home
  • SEARCH
  • 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 48709
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T16:19:21+00:00 2026-05-10T16:19:21+00:00

I’ve been battling PHP’s email reading functions for the better part of two days.

  • 0

I’ve been battling PHP’s email reading functions for the better part of two days. I’m writing a script to read emails from a mailbox and save any attachments onto the server. If you’ve ever done something similar, you might understand my pain: PHP doesn’t play well with email!

I’ve connected to the POP3 server and I can iterate the files. Here’s a rough outline of the code:

if (!$mbox = imap_open ('{myserver.com:110/pop3/notls}INBOX', 'u', 'p'))     die ('Cannot connect/check mail! Exiting');  if ($hdr = imap_check($mbox))      $msgCount = $hdr->Nmsgs; else      die ('Failed to get mail');  foreach ($overview as $message) {     $msgStruct = imap_fetchstructure($mbox, $message->msgno);      // if it has parts, there are attachments that need reading     if ($msgStruct->parts) {         foreach ($msgStruct->parts as $key => $part) {             switch (strtoupper($part->subtype)) {                 case 'GIF': case 'JPEG':case 'PNG':                      //do something - but what?!                      break;             }         }     } } 

I’ve marked where I’m stuck. I can use imap_fetchbody($mbox, $message->msgno, $key+1) but that gets me a bunch of data like this:

/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAUDBAQEAwUEBAQFBQUGBwwIBwcHBw8LCwkMEQ8S EhEPERETFhwXExQaFRERGCEYGh0dHx8fExciJCIeJBweHx7/2wBDAQUFBQcGBw4ICA4eFBEU Hh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh7/wAAR CAHiAi0DASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAA AgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkK FhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWG h4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl 5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREA ... 

I’m lead to believe that this is MIME data. I need it as an image! I’ve seen several classes bombing around the internet that claim to do the required wizardry. I can’t get any of them to work. I don’t understand why I’m finding this so hard!

In short, I’m looking for something that can turn a raw MIME string into real data.

  • 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. 2026-05-10T16:19:22+00:00Added an answer on May 10, 2026 at 4:19 pm

    I found a quick guide how to treat emails with PHP: here.

    At the bottom of that page there’s a attachment-body echo:

    if (substr($ContentType,0,4) == 'text') { echo imap_qprint($fileContent); } else { echo imap_base64($fileContent); } 

    I guess this is what you might need…

    (edit: in your case if it’s image always you can skip the if part. And of course, save the file instead of echoing it:)

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

Related Questions

Loading...

Sidebar

Ask A Question

Stats

  • Questions 55k
  • Answers 55k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer So, as a final followup to this question here is… May 11, 2026 at 7:36 am
  • added an answer I'd say (2) is your best bet. You've already talked… May 11, 2026 at 7:36 am
  • added an answer You can't do 'nested' inlines in the Django admin (i.e.… May 11, 2026 at 7:36 am

Top Members

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

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.