Advertisement
Guest User

Untitled

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