2013-04-05 3 views
1

POP3 메일 서버에서 다음 코드 가져 오기 메일을 사용하고 있습니다 .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); 
     } 
     } 
    } 

어떤 도움을 크게이다는

모든

답변

2

먼저 당신이 IMAP 코드를 사용하는 당신에게 appreciated.thank 그렇게해야 메일을 가져 와서 pop3 서버가 실행중인 imap 서비스를 가지고 있다고 가정합니다. IMAP 서비스를 사용하는 경우 명시 적으로 leave a copy of the mail in the server을 수행 할 필요가 없습니다. 메일이 삭제되거나 폴더에서 transh/junk로 이동되지 않는 한 메일은 서버에 남아 있습니다.

POP 서비스에도 동일하게 적용됩니다. 삭제 명령을 보내지 않으면 메일은 항상 서버에 남아 있습니다.