imap_deletemailbox
(PHP 4, PHP 5, PHP 7, PHP 8)
imap_deletemailbox — Delete a mailbox
参数
-
imap
IMAP\Connection 实例。
mailbox
-
The mailbox name, see imap_open() for more information
警告Passing untrusted data to this parameter is insecure, unless imap.enable_insecure_rsh is disabled.
更新日志
版本 | 说明 |
---|---|
8.1.0 |
现在 imap 参数接受 IMAP\Connection
实例,之前接受有效的 imap resource。
|
参见
- imap_createmailbox() - Create a new mailbox
- imap_renamemailbox() - Rename an old mailbox to new mailbox
-
imap_open() - Open an IMAP stream to a mailbox for the format of
mbox
+添加备注
用户贡献的备注 1 note
jab_creations at yahoo dot com ¶
3 days ago
I want to clarify a few technicalities to spare others the aggravation I had with imap_deletemailbox().
First off your first imap_open() should be to the folder to then imap_search() to ensure that the user isn't inadvertently deleting messages they're not yet aware of.
Secondly if !imap_search() you want to disconnect before executing imap_deletemailbox(). If you don't then you won't be able to avoid the following error:
PHP Request Shutdown: [CLOSED] IMAP connection broken (server response) (errflg=1)
That is because you just deleted the folder and the server doesn't know what to do with the connection so it triggers the error. So again, you want to delete the folder while you're connected to a different connection/folder combination instead.
A short example of how to cleanly delete a mail folder in PHP without triggering errors (presuming your connection configuration is correct):
<?php
$user = 'user@domain.tld';
$pass = '[pass here]';
$mail_server = '{imap.example.com:993/ssl/imap}';
$mail_connection_folder = imap_open($mail_server.$folder_string, $user, $pass);
if ($mail_connection_folder)
{
$mail_box_messages = imap_search($mail_connection_folder, 'ALL', SE_UID);
if (!$mail_box_messages)
{
$result = imap_close($mail_connection_folder);
$mail_connection_folder = imap_open($mail_server, $user, $pass);
$result = imap_deletemailbox($mail_connection_folder, imap_utf7_encode($mail_server.$folder_string));
}
else {}//messages in folder error.
}
else {}//Failed connection error.
?>
备份地址:http://www.lvesu.com/blog/php/function.imap-deletemailbox.php