title: How to get unread messages from server webmail in php
body: <p>I'm integrating webmail inbox access process. See my code is below. It does not get unread message it will bring all messages. How can i get only unread messages Kindly advice me. </p>
  
  <pre><code>$emails = imap_search($openmail, 'UNSEEN');
  </code></pre>
  
  <p>see above line it does not working. </p>
  
  <pre><code>$authhost="{example.com:110/pop3}INBOX";
  $username="xxx@example.com";
  $password="wxwxwxw";   
  
  ini_set('max_execution_time', 0);
  
  /* try to connect */
  $inbox = imap_open($authhost,$username,$password) or die('Cannot connect to Mail Server: ' . imap_last_error());
  
  /* grab emails */
  $emails = imap_search($inbox, 'UNSEEN');
  // echo count($emails);exit;
  
  /* if emails are returned, cycle through each... */
  if($emails) {
  
      /* begin output var */
      $output = '';
      /* put the newest emails on top */
      // rsort($emails);
      /* for every email... */
      // $count = 1;
  
      foreach($emails as $email_number) {
          $head = imap_header($inbox, $email_number);     
          /* get information specific to this email */
          $overview = imap_fetch_overview($inbox,$email_number,0);
  
          /*  echo "&lt;pre&gt;";
          print_r($overview);exit;  */
  
          $obj_thang = imap_headerinfo($inbox, $email_number);
          // print_r($overview);exit;
          $message = imap_body($inbox,$email_number,2);       
  
  
          /* output the email header information */       
          $output.= $obj_thang-&gt;subject;      
          //$output.= $obj_thang-&gt;fromaddress."&lt;br/&gt;";        
          $output.= $obj_thang-&gt;reply_toaddress."&lt;br/&gt;";      
      }
      echo $output;
  }
  </code></pre>