Advertisement
Guest User

Untitled

a guest
Nov 17th, 2016
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. <?php
  2. set_time_limit(4000);
  3. // Connect to gmail
  4. $imapPath = '{imap.gmail.com:993/imap/ssl}INBOX';
  5. $username = 'usenamer@gmail.com';
  6. $password = 'password';
  7. // try to connect
  8. $inbox = imap_open($imapPath,$username,$password,NULL,1) or die('Cannot connect to Gmail: ' . print_r(imap_errors()));
  9. $emails = imap_search($inbox,'UNSEEN');
  10. $output = '';
  11. foreach($emails as $mail) {
  12. $headerInfo = imap_headerinfo($inbox,$mail);
  13. $output .= $headerInfo->subject.'<br/>';
  14. $output .= $headerInfo->toaddress.'<br/>';
  15. $output .= $headerInfo->date.'<br/>';
  16. $output .= $headerInfo->fromaddress.'<br/>';
  17. $output .= $headerInfo->reply_toaddress.'<br/>';
  18. $emailStructure = imap_fetchstructure($inbox,$mail);
  19. if(!isset($emailStructure->parts)) {
  20. $output .= imap_body($inbox, $mail, FT_PEEK);
  21. } else {
  22. //
  23. }
  24. echo $output;
  25. $output = '';
  26. }
  27. // colse the connection
  28. imap_expunge($inbox);
  29. imap_close($inbox);
  30. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement