(PHP 4, PHP 5)

imap_mail_moveMove specified messages to a mailbox


bool imap_mail_move ( resource $imap_stream , string $msglist , string $mailbox [, int $options = 0 ] )

Moves mail messages specified by msglist to the specified mailbox.

Список параметров


Поток IMAP, полученный из imap_open().


msglist is a range not just message numbers (as described in » RFC2060).


The mailbox name, see imap_open() for more information


options is a bitmask and may contain the single option:

  • CP_UID - the sequence numbers contain UIDS

Возвращаемые значения

Возвращает TRUE в случае успешного завершения или FALSE в случае возникновения ошибки.



imap_mail_move() will flag the original mail with a delete flag, to successfully delete it a call to the imap_expunge() function must be made.

Смотрите также


This function copies the mail and then marks the source as deleted.  In order to see the changes, you must imap_expunge the source box.
1999-12-20 17:49:30
This function works, just not like everything else IMAP in PHP3... rather than feeding the server {server.ext/type:port}folder just feed it the folder's name.
2000-01-11 05:17:40
The syntax for the message list is defined in RFC2060
It is a string, containing a list of message numbers and ranges, separated by commas (no spaces anywhere.) For example, "1,2,5,11:15,19" would be accepted by imap_mail_copy or imap_mail_move.
A range of messages is defined as two message numbers separated by a colon (Ex. "1:10".) Also, a "*" may be used to refer to the last message in a mailbox. (Ex. "1:*" refers to all messages)
Be careful not to use the same mailbox for source and destination, especially if you expunge the mailbox immediately afterwards; the message will be copied (back over itself), flagged as deleted (by the imap_mail_move function), and then expunged.

The following code will move the messages in the $msg_no[] array from the folder in $mbox_name to the folder in $newmbox_name: ($mbox is an already-opened imap stream)

if ($mbox_name != $newmbox_name) {
$messageset implode (",",$msg_no);
2000-01-20 20:41:08
to complete the previous example, if the mbox/folders names are

and you want to copy/move from INBOX to INBOX/test this is the syntax:

$mbox = imap_open("{}INBOX",$mailuser,$mailpass)
      or die("can't connect: ".imap_last_error());

Hope this could help !
2001-08-17 15:28:42
I had the most trouble with figureing out what the message list was supposed to be.  There was one comment by but i was still terribly confused.  So I searched and searched and searched.  I read rfc2060 over 10 times.  Then BAM!  My brother found it here:

Here is the importand stuff. 

Another important field is the SEQUENCE, which identifies a set of messages by consecutive numbers from 1 to n where n is the number of messages in the mailbox.  A sequence may consist of a single number, a pair of numbers delimited by colon (equivalent to all numbers between those two numbers), or a list of single numbers or number pairs.  For example, the sequence 2,4:7,9,12:15 is equivalent to
   2,4,5,6,7,9,12,13,14,15 and identifies all those messages.

There is what I know about it.  BAM!
2002-07-17 05:28:48
This keeps biting me time after time. A lot of IMAP servers with quotas don't implement 'move' right - they do a 'copy&delete' instead and don't recognize that this conflicts with their quota implementetions. So, if you try to move a large message, you'll exceed your quota even though moving it does not increase the total size of your mailbox. This is not PHP-specific, but I bet it'll bite someone else besides me, so here you go.
2002-11-04 15:37:35
I've used a dot in
instead of
and it work's fine.
2003-01-27 12:18:31
To move mails via IMAP on an Exchange Server into "Gelschte Objekte" use:

imap_mail_move($mbox, $delmsg, "Gel&APY-schte Objekte");

It took me some tcpdumping to get this out, since both
imap_utf7_encode and

did not translate it right.

2003-07-09 12:06:49
After using imap_mail_move, imap_mail_copy or imap_delete it is necesary to call imap_expunge() function.
2005-11-21 03:36:14
I offer the following example because it took me HOURS to figure this out

->mailInBox imap_open($this->mailConnectString."INBOX"$this->accountLogin$this->accountPassword);

$this->messageCount imap_num_msg($this->mailInBox);
"Processing " $this->messageCount " messages:<Br>";
            for (
$i 1$i <= $this->messageCount; ++$i) {
$header imap_header($this->mailInBox$i);
$prettydate date("jS F Y"$header->udate);
$fromHost $header->from[0]->host;
                if (isset(
$header->from[0]->personal)) {
$personal $header->from[0]->personal;
                } else {
$personal $header->from[0]->mailbox;
$body imap_fetchbody($this->mailInBox$i"1.1");
                if (
$body == "") {
$body imap_fetchbody($this->mailInBox$i"1");

$move "INBOX.processed" date("Ymd");
"trying to move:" $i "<br>";

2007-07-05 01:49:25
To copy/move a mail in Gmail to a particular Folder like Starred/Spam/Drafts/Trash

use the following statement and don't forget to call CL_EXPUNGE or imap_expunge($mbox) after it.

($mbox,'16','[Gmail]/Starred'); // 16 is the message number, which can also be a range.(ex: '1:15')


Incase u want to send it to a personally created Label/folder(ex: Test) use..

2011-02-02 00:15:36

    Поддержать сайт на родительском проекте КГБ