2013-04-05 37 views
1

我使用以下代碼從我們的POP3郵件服務器獲取郵件server.i已成功獲取郵件。 我想離開這個郵件的副本在server.how我應該做的從pop3服務器獲取郵件並在郵件服務器中保留副本

<?php 
    /* connect to gmail */ 
    $hostname='{mail.xxx.com:110/pop3}INBOX'; 
    $username='[email protected]'; 
    $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); 
     } 
     } 
    } 

任何幫助是極大appreciated.thank你

回答

2

首先您使用的是IMAP碼取郵件,所以我假設你的pop3服務器也有imap服務。如果您使用的是IMAP服務,則不需要明確地執行leave a copy of the mail in the server。郵件將保留在服務器上,除非它們被刪除或從文件夾移動到移動/垃圾郵件。

同樣適用於POP服務。郵件將始終保留在服務器上,除非您發送刪除命令。