[英]How to move a mail message to a folder with php imap
我似乎无法将邮件移动到保存的文件夹中。 这是我的代码:
$mbox = imap_open("{".$mail_server.":".$mail_port."}".$mail_folder,
$mail_username, $mail_password) or die("Error opening mailbox: ".imap_last_error());
$countnum = imap_num_msg($mbox);
$msglist = array();
if( $countnum > 0 ) {
$num = 1;
while ($num <= $countnum) {
$msglist[] = $num;
$num++;
}//end while loop
}
//move the email to our saved folder
imap_mail_move($mbox,implode(',',$msglist),'INBOX/Saved');
imap_expunge($mbox);
imap_close($mbox);
当我运行此脚本时,什么都没有发生。 邮件保留在收件箱中。 有什么想法吗? 谢谢!
通过查看imap-mail-move()的文档,我看到您已将范围与粘在一起,
并且从1开始计数,因此不需要for循环:
<?php
$mbox = imap_open("{".$mail_server.":".$mail_port."}INBOX", $mail_username, $mail_password) or die("Error opening mailbox: ".imap_last_error());
$countnum = imap_num_msg($mbox);
if($countnum > 0) {
//move the email to our saved folder
$imapresult=imap_mail_move($mbox,'1:'.$countnum,'INBOX/Saved');
if($imapresult==false){die(imap_last_error());}
imap_close($mbox,CL_EXPUNGE);
}
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.