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);
?>
오류가 있습니까? 그렇다면 어떤 것들입니까? – Tim
더 나은 답변을 제공하는 사람들을 돕기 위해받은 오류에 대한 추가 정보 제공 –
오류가 발생하지 않았으므로 그 부분이 잘못되어 혼란 스럽습니다. – user1788261