user6096423
user6096423

Reputation: 141

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}", "[email protected]", "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.

Upvotes: 0

Views: 1304

Answers (2)

user6096423
user6096423

Reputation: 141

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

$host="{myserver.com:143/notls}";
$user="[email protected]";
$pass="password";

$imap=imap_open( $host, $user, $pass );

This works with the Horde webmail

Upvotes: 0

cweiske
cweiske

Reputation: 31088

You're using IMAP commands on a POP3 port. POP3 only allows fetching and deleting (See RFC 1939).

Use a real IMAP connection, and then imap_mail_move will work.

Upvotes: 1

Related Questions