Search code examples
phpimap

Moving an email with imap in PHP


I have tried a number of ways to get a file to move out of the INBOX after I process it, but it seems all the PHP methods for imap_mail_copy, and imap_mail_move are not firing for me. Why imap_delete works and the others don't is a mystery to me.

This is what I have tried:

<?
$imap = imap_open("{mail.myserver.com:995/pop3/ssl/novalidate-cert}", "sample@myserver.com", "password");

if( $imap ) {
$num = imap_num_msg($imap);

if( $num >0 ) {


//imap_copy($imap, $num, "INBOX.Drafts"); --> illegal function 

//imap_mail_copy($imap, $num, "INBOX.Drafts"); --> throws "Copy not valid for POP3 (errflg=2)" error
//imap_mail_copy($imap, $num, "INBOX/Drafts"); --> throws "Copy not valid for POP3 (errflg=2)" error
//imap_mail_copy($imap, $num, "Drafts"); --> throws "Copy not valid for POP3 (errflg=2)" error


//imap_mail_move($imap, $num, "INBOX.Drafts"); --> throws "Copy not valid for POP3 (errflg=2)" error
//imap_mail_move($imap, $num, "INBOX/Drafts"); --> throws "Copy not valid for POP3 (errflg=2)" error
//imap_mail_move($imap, $num, "Drafts"); --> throws "Copy not valid for POP3 (errflg=2)" error

//imap_delete($imap, $num); --> this works, but I lose the email, which I dont want

imap_expunge($imap);

}
imap_close($imap);
} 
?>

I was wondering, since 'imap_delete' works, maybe there is some other php function that can move or copy the email to another folder.


Solution

  • The solution has to do with the server syntax, not the PHP code:

    $host="{myserver.com:143/notls}";
    $user="sample@myserver.com";
    $pass="password";
    
    $imap=imap_open( $host, $user, $pass );
    

    This works with the Horde webmail