Advertisement
Guest User

Untitled

a guest
Jan 18th, 2016
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. set_time_limit(4000);
  2. /* connect to gmail */
  3. $hostname = '{imap.gmail.com:993/imap/ssl}INBOX';
  4. $username = 'sample@gmail.com';
  5. $password = '123';
  6.  
  7. /* try to connect */
  8. $inbox = imap_open($hostname,$username,$password) or die('Cannot connect to Gmail: ' . imap_last_error());
  9.  
  10. /* grab emails */
  11. $emails = imap_search($inbox,'ALL');
  12.  
  13. /* if emails are returned, cycle through each... */
  14. if($emails) {
  15. $output = '';
  16. rsort($emails);
  17.  
  18. foreach($emails as $email_number) {
  19. $overview = imap_fetch_overview($inbox,$email_number,0);
  20. /* if($overview[0]->from=='sample1@gmail.com')
  21. { */
  22. $structure = imap_fetchstructure($inbox, $email_number);
  23.  
  24. if(isset($structure->parts) && is_array($structure->parts) && isset($structure->parts[1])) {
  25. $part = $structure->parts[1];
  26. $message = imap_fetchbody($inbox,$email_number,2);
  27.  
  28. if($part->encoding == 3) {
  29. $message = imap_base64($message);
  30. } else if($part->encoding == 1) {
  31. $message = imap_8bit($message);
  32. } else {
  33. $message = imap_qprint($message);
  34. }
  35. }
  36.  
  37. $output.= '<div class="toggle'.($overview[0]->seen ? 'read' : 'unread').'">';
  38. $output.= '<span class="from">From: '.utf8_decode(imap_utf8($overview[0]->from)).'</span>';
  39. $output.= '<span class="date">on '.utf8_decode(imap_utf8($overview[0]->date)).'</span>';
  40. $output.= '<br /><span class="subject">Subject('.$part->encoding.'): '.utf8_decode(imap_utf8($overview[0]->subject)).'</span> ';
  41. $output.= '</div>';
  42.  
  43. $output.= '<div class="body">'.$message.'</div><hr />';
  44. //}
  45. }
  46.  
  47. echo $output;
  48.  
  49. }
  50.  
  51. imap_close($inbox);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement