2012-10-31 3 views
0

Gmail 계정에서 읽지 않은 이메일을 가져 오는 방법을 알고 싶습니다. Gmail 계정의 모든 읽지 않은 이메일이 PHP를 통해 내 사이트로 전송되기를 원하는 Gmail 계정이 있습니다. 나는 다양한 코드를 구현하고 있지만 그들은 나를 도와주지 않습니다. 이 문제를 해결하도록 도와주세요.Gmail에서 읽지 않은 이메일을 가져오고 싶습니다.

나는 Gmail에서 메일을 가져 오는 데 사용하는 코드가 있지만 메일은 가져 오지 않습니다.

<?php 
/* connect to gmail */ 

$hostname = '{imap.gmail.com:993/imap/ssl}INBOX'; 
$username = '[email protected]'; 
echo $password = 'abcd'; 

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

/* if emails are returned, cycle through each... */ 
if($emails) { 
    echo "got 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); 
    $message = imap_fetchbody($inbox,$email_number,2); 

    /* 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>'; 
    break; 
    } 

    echo $output; 
} 

/* close the connection */ 
imap_close($inbox); 
?> 
+3

오류가 있습니까? 그렇다면 어떤 것들입니까? – Tim

+1

더 나은 답변을 제공하는 사람들을 돕기 위해받은 오류에 대한 추가 정보 제공 –

+0

오류가 발생하지 않았으므로 그 부분이 잘못되어 혼란 스럽습니다. – user1788261

답변

1

사용 imap_open :

$inbox = imap_open("{imap.gmail.com:993/imap/ssl}INBOX",$username,$password); 

는 예를 들어 here를 참조하십시오. 읽지 않은 메시지를 가져 오는에 대한

+0

오! 나는 장님 이었음에 틀림 없다. –

+0

나는이 질문에 대해 OP가 비난하고 있다고 비난하고 있습니다. 의심의 여지가 없습니다. – NewUser

+0

문제 없습니다. 나는 단지 내가 그것을 알아 차렸음에 틀림 없다고 느낀다. ;) –

2

는 수행

$inbox = imap_open($hostname,$username,$password) or die('Cannot connect to Gmail: ' . imap_last_error()); 
$unread_msgs = imap_search($inbox, 'UNSEEN'); 

이 다른 옵션을뿐만 아니라 해당 manual를 참조 할 수 있습니다.

관련 문제