Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- set_time_limit(4000);
- /* connect to gmail */
- $hostname = '{imap.gmail.com:993/imap/ssl}INBOX';
- $username = 'sample@gmail.com';
- $password = '123';
- /* try to connect */
- $inbox = imap_open($hostname,$username,$password) or die('Cannot connect to Gmail: ' . imap_last_error());
- /* grab emails */
- $emails = imap_search($inbox,'ALL');
- /* if emails are returned, cycle through each... */
- if($emails) {
- $output = '';
- rsort($emails);
- foreach($emails as $email_number) {
- $overview = imap_fetch_overview($inbox,$email_number,0);
- /* if($overview[0]->from=='sample1@gmail.com')
- { */
- $structure = imap_fetchstructure($inbox, $email_number);
- if(isset($structure->parts) && is_array($structure->parts) && isset($structure->parts[1])) {
- $part = $structure->parts[1];
- $message = imap_fetchbody($inbox,$email_number,2);
- if($part->encoding == 3) {
- $message = imap_base64($message);
- } else if($part->encoding == 1) {
- $message = imap_8bit($message);
- } else {
- $message = imap_qprint($message);
- }
- }
- $output.= '<div class="toggle'.($overview[0]->seen ? 'read' : 'unread').'">';
- $output.= '<span class="from">From: '.utf8_decode(imap_utf8($overview[0]->from)).'</span>';
- $output.= '<span class="date">on '.utf8_decode(imap_utf8($overview[0]->date)).'</span>';
- $output.= '<br /><span class="subject">Subject('.$part->encoding.'): '.utf8_decode(imap_utf8($overview[0]->subject)).'</span> ';
- $output.= '</div>';
- $output.= '<div class="body">'.$message.'</div><hr />';
- //}
- }
- echo $output;
- }
- imap_close($inbox);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement