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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T19:27:39+00:00 2026-06-16T19:27:39+00:00

I am using Zend_Mail_Storage_Imap library to retrieve e-mails from IMAP. $mail = new Zend_Mail_Storage_Imap(array(‘connection

  • 0

I am using Zend_Mail_Storage_Imap library to retrieve e-mails from IMAP.

$mail = new Zend_Mail_Storage_Imap(array('connection details'));
foreach($mail as $message)
{
  if($message->date > $myDesiredDate)
  {
    //do stuff
  }else{
    continue;
  }

This code retrieves all the mails with the oldest mail retrieved first. The variable $myDesiredDate is the date/time, mails beyond which are not needed. Is there a way to skip the retrieval of all the mails and check each mail’s date one by one? If not, can I reverse the $mail object to get the latest email at the top ?

UPDATE: I have now modified the code a little, to start from the latest mail and checking the date time of the current mail. The moment I encounter an email with the time beyond which I don’t want to parse emails, I break the loop.

    //time upto which I want to fetch emails (in seconds from current time)
    $time = 3600;
    $mail = new Zend_Mail_Storage_Imap(array('connection details'));
    //get total number of messages
    $total = $mail->countMessages()

    //loop through the mails, starting from the latest mail
    while($total>0)
    {
      $mailTime = strtotime(substr($mail->getMessage($total)->date,0,strlen($mail->getMessage($total)->date)-6));

      //check if the email was received before the time limit
      if($mailTime < (time()-$time))
        break;
      else
        //do my thing

      $total--;
    }

    //close mail connection

$mail->close();

The only thing that I am concerned here is, whether I shall get the mails in the correct order or not, if I start from mail count to 0 ?

  • 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-16T19:27:41+00:00Added an answer on June 16, 2026 at 7:27 pm

    Since, my code is working absolutely fine, I shall include this as an answer (quick and dirty).I now start from the latest mail and check the date time of the current mail. The moment I encounter an email with the time beyond which I don’t want to parse emails, I break the loop.

        //time upto which I want to fetch emails (in seconds from current time)
        $time = 3600;
        $mail = new Zend_Mail_Storage_Imap(array('connection details'));
        //get total number of messages
        $total = $mail->countMessages()
    
        //loop through the mails, starting from the latest mail
        while($total>0)
        {
          $mailTime = strtotime(substr($mail->getMessage($total)->date,0,strlen($mail->getMessage($total)->date)-6));
    
          //check if the email was received before the time limit
          if($mailTime < (time()-$time))
            break;
          else
            //do my thing
    
          $total--;
        }
    
        //close mail connection
    
    $mail->close();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Zend Mail library to access email and download email attachments. Is there
I'm using zend mail extended with zend_mail_storage_imap and I built an application that looks
i'm using Zend_Mail to send out an email from Aruba PEC. $config = array('auth'=>'login',
I want to send email using Zend Mail library. How I have to include
I am using Zend Mail as follows: $transport = new Zend_Mail_Transport_Smtp($smtpSettings['smtpServer'], $smtpSettings); $mail =
How can I check if an email folder exists using Zend_Mail_Storage_Imap, theres a createFOlder,
I'm trying to get into the IMAP server with OAuth, using the PHP Sample
I am using Zend Framework to send mail. It's doing something very odd, the
Hi guys for some weird reason I'm unable to send email using zend mail
I'm using Zend_Mail and the following code to send my email messages. $mail =

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.