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 6712363
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:15:02+00:00 2026-05-26T08:15:02+00:00

I am pretty new when it comes to handling emails in php. Basically I

  • 0

I am pretty new when it comes to handling emails in php.

Basically I need to read a pop3 mailbox and save the messages to a database and the attachments to a folder. Then mail that same mail (slightly altered) back to another email recipient.

I thought I got this all working, then I realized when the attachment is another mail message I only receive the body as text (after base64_decode).

Is it possible to save an attached email to a file and then send it as attachment in another message?

Any help will be appreciated.

Here is some code to put it into perspective :

// This is the IMAP connection: imap_open("{"."$host:$port/pop3$ssl"."}$folder",$user,$pass,OP_SILENT);
$mailConnection = $this->Maildata->mail_login($host,$port,$user,$pass,$folder,$ssl);

// This retrieves the list of mails in the current folder
$messageList = $this->Maildata->mail_list($mailConnection,$message);
foreach ($messageList as $messageId => $messageListData) {

    // This reads the mail object into an array
    $mailMessage = $this->Maildata->mail_mime_to_array($mailConnection,$messageId,true);

    // This loops through each mail
    foreach ($mailMessage as $tmpId => $tmpData) {
        // Excluded save to database since it is unrelated

        // This checks if item is an attachment and saves it.
        if (isset($tmpData['is_attachment']) && $tmpData['is_attachment'] === true) {
            $tmpName = date('Y-m-d H:i:s', strtotime('now'));
            $this->Maildata->mail_attachment_save($tmpData['data'], $tmpName .$tmpData['name']);
        }
    }
}

P.S. This all works, but imap_fetchbody($mailConnection , $messageId, $prefix); doesn’t seem to send all the data I need.

  • 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-26T08:15:03+00:00Added an answer on May 26, 2026 at 8:15 am

    Yes.

    You can save attached mail messages as a file, but it will not be in a format that Microsoft Office Outlook will understand. Interestingly enough if you save the file as a .eml then windows live mail will handle the message perfectly.

    No webmail service handles attached mail items as outlook and windlows live mail does and gmail ignores them completely.

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

Sidebar

Related Questions

I am pretty new to WCF in general. What little experience I have comes
I pretty new to Objective-C (and C itself) and need to consume a NSData
I am pretty new to php, but I am learning! I have a simple
Background I'm not new to programming, however I am when it comes to handling
I'm pretty new to Java, and I need to build up programming environments for
I am pretty new to python. I need to create a class that loads
Im pretty new to Java Web Services, but I cant find a good explanation
I'm pretty new to my company (2 weeks) and we're starting a new platform
I'm a pretty new C# and .NET developer. I recently created an MMC snapin
I'm pretty new to the idea of recursion and this is actually my first

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.