简体   繁体   English

在PHP中使用imap移动电子邮件

[英]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. 我尝试了多种方法来处理文件,然后将文件从INBOX中移出,但是imap_mail_copy和imap_mail_move的所有PHP方法似乎都不适合我。 Why imap_delete works and the others don't is a mystery to me. 为什么imap_delete起作用而其他人不起作用,这对我来说还是个谜。

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. 我想知道,既然'imap_delete'有效,也许还有其他一些php函数可以将电子邮件移动或复制到另一个文件夹。

You're using IMAP commands on a POP3 port. 您正在POP3端口上使用IMAP命令。 POP3 only allows fetching and deleting (See RFC 1939 ). POP3仅允许获取和删除(请参阅RFC 1939 )。

Use a real IMAP connection, and then imap_mail_move will work. 使用真实的IMAP连接,然后imap_mail_move将起作用。

The solution has to do with the server syntax, not the PHP code: 解决方案与服务器语法有关,而不与PHP代码有关:

$host="{myserver.com:143/notls}";
$user="sample@myserver.com";
$pass="password";

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

This works with the Horde webmail 这适用于部落网络邮件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM