Advertisement
Guest User

Untitled

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