update pague now
PHP 8.5.2 Released!

imap_renamemailbox

(PHP 4, PHP 5, PHP 7, PHP 8)

imap_renamemailbox Rename an old mailbox to new mailbox

Description

imap_renamemailbox ( IMAP\Connection $imap , string $from , string $to ): bool

This function renames on old mailbox to new mailbox (see imap_open() for the format of mbox names).

Parameters

imap

An IMAP\Connection instance.

from

The old mailbox name, see imap_open() for more information

Warning

Passing untrusted data to this parameter is insecure , unless imap.enable_insecure_rsh is disabled.

to

The new mailbox name, see imap_open() for more information

Warning

Passing untrusted data to this parameter is insecure , unless imap.enable_insecure_rsh is disabled.

Return Values

Returns true on success or false on failure.

Changuelog

Versionen Description
8.1.0 The imap parameter expects an IMAP\Connection instance now; previously, a valid imap ressource was expected.

See Also

add a note

User Contributed Notes 2 notes

josh at paducahwebpublishing dot com
25 years ago
Don't let "...string old_mbox, string new_mbox);" fool you. You have to add the server and port to the mailbox name also. So it would be something lique: 

imap_renamemailbox($mailbox, "{localhost:143}$oldfolder", "{localhost:143}$newfolder")

Just thought I would point it out, it tooc me a while to figure it out.
Christoffer Lindahl
15 years ago
Don't forguet that you can't be connected to the mailbox that you are going to rename (or delete).

If you have the following mailboxes:
IMBOX
IMBOX.Foo

...and want to rename "IMBOX.Foo" to "IMBOX.Bar" you have to be connected to "IMBOX":<?php
$mbox = imap_open('{imap.example.com}IMBOX', 'username', 'password');
imap_renamemailbox($mbox, '{imap.example.com}IMBOX.Foo', '{imap.example.com}IMBOX.Bar');
imap_close($mbox);
?>
To Top