函数名:imap_getmailboxes()
适用版本:PHP 4, PHP 5, PHP 7
用法:imap_getmailboxes(resource $imap_stream, string $ref, string $pattern)
说明:该函数用于获取指定邮箱中的目录列表。
参数:
返回值:返回一个包含邮箱目录信息的数组,如果失败则返回 FALSE。
示例:
// 连接到 IMAP 服务器
$imap_stream = imap_open("{imap.example.com:993/imap/ssl}", "username", "password");
if ($imap_stream) {
// 获取邮箱目录列表
$mailboxes = imap_getmailboxes($imap_stream, "{imap.example.com}", "*");
if ($mailboxes) {
foreach ($mailboxes as $mailbox) {
echo "Mailbox name: " . $mailbox->name . "<br>";
echo "Mailbox delimiter: " . $mailbox->delimiter . "<br>";
echo "Mailbox attributes: " . $mailbox->attributes . "<br>";
echo "Mailbox flags: " . $mailbox->flags . "<br><br>";
}
} else {
echo "Failed to get mailboxes.";
}
// 关闭 IMAP 连接
imap_close($imap_stream);
} else {
echo "Failed to connect to IMAP server.";
}
注意事项: