email - IMAP, PHP returns no messeges -
i have connection server username , password. connects resource id of 2. displays status correctly, listing amount of unread emails in inbox, recent mail etc. when comes imap_num_msg() function, pass in correct argument returns 0. doing wrong return 0?
<?php $mbox = imap_open("{imap.gmail.com:993/imap/ssl}inbox", "xxxxx", "xxxxxx", op_halfopen) or die("can't connect: " . imap_last_error()); $list = imap_list($mbox, "{imap.gmail.com:993/imap/ssl}inbox", "*"); if (is_array($list)) { foreach ($list $val) { echo imap_utf7_decode($val) . "\n"; } } else { echo "imap_list failed: " . imap_last_error() . "\n"; } $status = imap_status($mbox, "{imap.gmail.com:993/imap/ssl}inbox", sa_all); if ($status) { echo "messages: " . $status->messages . "<br />\n"; echo "recent: " . $status->recent . "<br />\n"; echo "unseen: " . $status->unseen . "<br />\n"; echo "uidnext: " . $status->uidnext . "<br />\n"; echo "uidvalidity:" . $status->uidvalidity . "<br />\n"; } else { echo "imap_status failed: " . imap_last_error() . "\n"; } $nummessages = imap_num_msg($mbox); if ($nummessages) { echo $nummessages; } else { echo "imap_status failed: " . imap_last_error() . "\n"; } imap_close($mbox); ?>
solved it, solution set flag in imap_open() function op_readonly opens mailbox.
<?php $mbox = imap_open("{imap.gmail.com:993/imap/ssl}inbox", "xxxxxx", "xxxxxx", op_readonly, 1) or die("can't connect: " . imap_last_error()); ?>
Comments
Post a Comment