Using PHP's IMAP functions, I want to move 10 messages from the folder "xyz_msg" to the folder "xyz_tmp"

Below is the code I use to connect to the email server.

<?php 
 
$mbox = imap_open ("{imap.gmail.com:993/imap/ssl/novalidate-cert}xyz_tmp", "example@gmail.com", "password") 
     or die("can't connect: " . imap_last_error());  
 
$imap_obj = imap_check($mbox); 
echo "<pre>"; 
var_dump($imap_obj); 
echo "</pre>"; 
 
$check = imap_mailboxmsginfo($mbox); 
 
if ($check) { 
    echo "Date: "     . $check->Date    . "<br />\n" ; 
    echo "Driver: "   . $check->Driver  . "<br />\n" ; 
    echo "Mailbox: "  . $check->Mailbox . "<br />\n" ; 
    echo "Messages: " . $check->Nmsgs   . "<br />\n" ; 
    echo "Recent: "   . $check->Recent  . "<br />\n" ; 
    echo "Unread: "   . $check->Unread  . "<br />\n" ; 
    echo "Deleted: "  . $check->Deleted . "<br />\n" ; 
    echo "Size: "     . $check->Size    . "<br />\n" ; 
} else { 
    echo "imap_check() failed: " . imap_last_error() . "<br />\n"; 
} 
 
imap_close($mbox); 
 
?>

Recommended Answers

All 3 Replies

Could you provide a better description of your code (perhaps php comments) and describe in more detail why you can't do it. The theory behind it is you search through to inbox in a loop then as you retrieve them the messages go through an if statement and if that if statement passes then it will transfer that message across one by one in the loop.

Thank you cwarn23 for your reply.

My code will connect to the server but it doesn't move anything. I don't know what function to use that will move 10 messages from one folder to another folder.

Could you provide a better description of your code (perhaps php comments) and describe in more detail why you can't do it. The theory behind it is you search through to inbox in a loop then as you retrieve them the messages go through an if statement and if that if statement passes then it will transfer that message across one by one in the loop.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.