如何使用php imap将邮件移动到文件夹 [英] How to move a mail message to a folder with php imap

查看:177
本文介绍了如何使用php imap将邮件移动到文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎无法将邮件移动到保存的文件夹中.这是我的代码:

I can't seem to move my mail messages to my saved folder. Here is my code:

$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);

当我运行此脚本时,什么都没有发生.邮件保留在收件箱中.有什么想法吗?谢谢!

When I run this script nothing happens. The message stays in the inbox. Any thoughts? Thanks!

推荐答案

通过查看 imap-mail-move()我看到您已经将范围与,粘在一起,并且从1开始计数,所以不需要for循环:

From looking at the docs for imap-mail-move() I see you've glued your range together with , and your counting up from 1 so theres no need for the for loop:

<?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);
}
?>

这篇关于如何使用php imap将邮件移动到文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆