Advertisement
Guest User

Untitled

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