dshakcsq64956 2015-11-20 21:13
浏览 28
已采纳

PHP从IMAP邮件帐户中删除旧邮件

I am trying to access a IMAP webmail account in order to delete old messages using php. The script I have so far is:

<?php

$del = new DateTime();
$del->modify('-1 month');

$mbox = imap_open("{imap.test.com:993/imap/ssl}INBOX", "username", "password")
 or die("can't connect: " . imap_last_error());

$MC = imap_check($mbox);

// Fetch an overview for all messages in INBOX
$result = imap_fetch_overview($mbox,"1:{$MC->Nmsgs}",0);
foreach ($result as $overview) {
    $date = $overview->date;
    $date = DateTime::createFromFormat('D, d M Y H:i:s O', $date); 

    if($date<$del) {
        imap_delete($mbox,$overview->msgno);
    }

}   
imap_expunge($mbox);
imap_close($mbox);
?>

The code is now correct. But the web hosting service does not allow scripted access to their IMAP server from localhost

  • 写回答

2条回答 默认 最新

  • drutjkpsr67393592 2015-11-20 21:23
    关注

    You need a semicolon on this line:

    imap_expunge($mbox);
    

    when PHP can't be parsed it returns a 500 error.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效