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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:49:17+00:00 2026-06-01T15:49:17+00:00

i am developing a site in which users can mail tickets and attach any

  • 0

i am developing a site in which users can mail tickets and attach any type of files to a specific mail id. I need to add the mail subject, content and attachment to the database. I am doing this using cron. Except the attachments every thing works perfect. I have seen some post which create download links. Since i am using cron i can’t do it manually.

        $hostname = '{xxxx.net:143/novalidate-cert}INBOX';
        $username = 'yyy@xxxx.net';
        $password = 'zzzz';
        /* try to connect */
        $inbox = imap_open($hostname,$username,$password) or die('Cannot connect to : ' . imap_last_error());
        $emails = imap_search($inbox,'ALL');

                if($emails) {
          $output = '';
          rsort($emails);
          foreach($emails as $email_number) {
            $structure = imap_fetchstructure($inbox, $email_number); 
            $name = $structure->parts[1]->dparameters[0]->value; // name of the file
            $type = $structure->parts[1]->type; //type of the file 
}}

I am able to get type and name of the files but don’t know how to proceed further

Any one please help me. thank you…

  • 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-06-01T15:49:18+00:00Added an answer on June 1, 2026 at 3:49 pm

    To save attachments as files, you need to parse the structure of the message and take out all parts that are attachments on it’s own (content disposition). You should wrap that into classes of their own so you have an easy access and you can handle errors more easily over time, email parsing can be fragile:

    $savedir = __DIR__ . '/imap-dump/';
    
    $inbox = new IMAPMailbox($hostname, $username, $password);
    $emails = $inbox->search('ALL');
    if ($emails) {
        rsort($emails);
        foreach ($emails as $email) {
            foreach ($email->getAttachments() as $attachment) {
                $savepath = $savedir . $attachment->getFilename();
                file_put_contents($savepath, $attachment);
            }
        }
    }
    

    The code of these classes is more or less wrapping the imap_... functions, but for the attachment classes, it’s doing the parsing of the structures as well. You find the code on github. Hope this is helpful.

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

Sidebar

Related Questions

I just started developing a multilingual webpage which site users can read and post
I'm developing an international site which uses UTF8 to display non english characters. I'm
I am currently developing a site for a client which uses the JQuery cycle
I'm developing a site which has urls like this: site.com/james site.com/james/photos Schema for this
I am developing an annual report site which needs to be compatible with major
I'm developing a site using the CakePHP framework. I have a form which shows
I am developing as site for mobile devices which requires the user to select
I'm trying to set up a site which allows users to create their own
I am currently developing a site using SSL that requires users to be able
I am developing a trading site. Users will post some price, $100, $120 for

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.