Bad Message Number in IMAP

Hi,
I am a php beginner and I am working on a mail parser. For that, I am going through PHP’s IMAP functions which I wrote inside a mailParser class.

function __construct(){
    $this->stream = imap_open($this->server,$this->username,$this->password) or 
    die('Cannot connect to Gmail'.imap_last_error());
}

When I ran this:

function getInboxHeaders(){
    imap_headers($this->stream);
    $tot_msg = imap_num_msg($this->stream);

    for($count=$tot_msg;$count>-1;$count--){
        $header = imap_header($this->stream,$count);
        print_r($header);
    }
 }

inorder to get the headers of the messages on my Inbox, I was notified of the warning “Bad message number”. Why do I get such a warning upon running this function?

I am really hoping that somebody could know the reason behind this.

Sponsor our Newsletter | Privacy Policy | Terms of Service