Advertisement
Guest User

Untitled

a guest
Oct 10th, 2016
304
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. $hostname = '{imap.gmail.com:993/imap/ssl}INBOX';
  2. $username = 'my.example@gmail.com';
  3. $password = 'myexample';
  4. $inbox = imap_open($hostname,$username,$password) or die('Cannot connect to Gmail: ' . imap_last_error());
  5.  
  6. $emails = imap_search($inbox,'ALL');
  7.  
  8. if($emails) {
  9.  
  10. $output = '';
  11.  
  12. /* put the newest emails on top */
  13. rsort($emails);
  14.  
  15. /* for every email... */
  16. foreach($emails as $email_number) {
  17.  
  18. /* get information specific to this email */
  19. $overview = imap_fetch_overview($inbox,$email_number,0);
  20. $message = imap_fetchbody($inbox,$email_number,2);
  21.  
  22. /* output the email header information */
  23. $output.= '<div class="toggler '.($overview[0]->seen ? 'read' : 'unread').'">';
  24. $output.= '<span class="subject">'.$overview[0]->subject.'</span> ';
  25. $output.= '<span class="from">'.$overview[0]->from.'</span>';
  26. $output.= '<span class="date">on '.$overview[0]->date.'</span>';
  27. $output.= '</div>';
  28.  
  29. /* output the email body */
  30. $output.= '<div class="body">'.$message.'</div>';
  31. }
  32.  
  33. echo $output;
  34. }
  35. imap_close($inbox);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement