Guest User

Untitled

a guest
Jun 30th, 2018
473
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.31 KB | None | 0 0
  1. <?php
  2. /* connect to gmail */
  3. $hostname = '{imap.gmail.com:993/imap/ssl}INBOX';
  4. $username = 'user@gmail.com';
  5. $password = 'password';
  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.  
  16.   /* begin output var */
  17.   $output = '';
  18.  
  19.   /* put the newest emails on top */
  20.   //rsort($emails);
  21.  
  22.   /* for every email... */
  23.   foreach($emails as $email_number) {
  24.    
  25.     /* get information specific to this email */
  26.     $overview = imap_fetch_overview($inbox,$email_number,0);
  27.     $message = imap_fetchbody($inbox,$email_number,2);
  28.    
  29.      echo base64_decode($message);
  30.      
  31.      
  32.     /* output the email header information */
  33.     //$output.= '<div class="toggler '.($overview[0]->seen ? 'read' : 'unread').'">';
  34.     //$output.= '<span class="subject">'.$overview[0]->subject.'</span> ';
  35.     //$output.= '<span class="from">'.$overview[0]->from.'</span>';
  36.     //$output.= '<span class="date">on '.$overview[0]->date.'</span>';
  37.     //$output.= '</div>';
  38.    
  39.     /* output the email body */
  40.     //$output.= '<div class="body">'.$message.'</div>';
  41.   }
  42.  
  43.  
  44. }
  45.  
  46. /* close the connection */
  47. imap_close($inbox);
  48. ?>
Add Comment
Please, Sign In to add comment