【问题标题】:Fetching mail from pop3 server and leaving copy in the mail server从 pop3 服务器获取邮件并将副本留在邮件服务器中
【发布时间】:2013-04-05 06:03:50
【问题描述】:

我正在使用以下代码从我们的 POP3 邮件服务器获取邮件。我已成功获取邮件。 我想在服务器上留下一份邮件副本。我应该怎么做

    <?php
    /* connect to gmail */
    $hostname='{mail.xxx.com:110/pop3}INBOX';
    $username='yyy.xxx@xxx.com';
    $password='xxx_9851';



    /* try to connect */
           $inbox = imap_open($hostname,$username,$password) or die('Cannot connect to Gmail: ' . imap_last_error());
    echo "here";

    /* grab emails */
    $emails = imap_search($inbox,'SUBJECT "hi"');/* if emails are returned, cycle through each... */
    //print_r($emails);
    if($emails) {

      /* begin output var */
      $output = '';

      /* put the newest emails on top */
      rsort($emails);

      /* for every email... */
      foreach($emails as $email_number) {

        /* get information

 specific to this email */
    $overview = imap_fetch_overview($inbox,$email_number,0);
    echo "<pre>";
//  print_r($overview);
    $message = imap_fetchbody($inbox,$email_number,2);
    $header=imap_fetchheader($inbox,$email_number);
//print_r($message);
//print_r($header);
    /* output the email header information */
    $output.= '<div class="toggler '.($overview[0]->seen ? 'read' : 'unread').'">';
    $output.= '<span class="subject">'.$overview[0]->subject.'</span> ';
    $output.= '<span class="from">'.$overview[0]->from.'</span>';
    $output.= '<span class="date">on '.$overview[0]->date.'</span>';
    $output.= '</div>';

    /* output the email body */
    $output.= '<div class="body">'.$message.'</div>';

     $s = imap_fetchstructure($inbox,$email_number);
    // print_r ($s->parts);
        if (!$s->parts) 
        {// simple
       // getpart($inbox,$email_number,$s,0);  // pass 0 as part-number
        }
        else {  // multipart: cycle through each part
        foreach ($s->parts as $partno0=>$p){
          attachment_to_file($inbox,$email_number,$p,$partno0+1);
        }
        }
  }

非常感谢任何帮助。谢谢

【问题讨论】:

    标签: php email pop3


    【解决方案1】:

    首先,您使用 IMAP 代码来获取邮件,所以我假设您的 pop3 服务器也运行 imap 服务。如果您使用的是 IMAP 服务,则无需明确执行 leave a copy of the mail in the server。邮件将保留在服务器上,除非它们被删除或从文件夹移动到 transh/junk。

    同样适用于 POP 服务。除非您发送删除命令,否则邮件将始终保留在服务器上。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-10-05
      • 1970-01-01
      • 2017-09-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多