Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. public function test()
  2. {
  3. /* connect to gmail */
  4. $hostname = '{imap.gmail.com:993/imap/ssl}INBOX';
  5. $username = 'youremail';
  6. $password = 'yourpassword';
  7.  
  8. $inbox = imap_open($hostname, $username, $password) or die('Cannot connect: ' . imap_last_error());
  9.  
  10. $emails = imap_search($inbox, 'ALL');
  11.  
  12.  
  13. if ($emails) {
  14. $output = '';
  15.  
  16. rsort($emails);
  17.  
  18. foreach ($emails as $email_number) {
  19. $header = imap_headerinfo($inbox, $email_number);
  20.  
  21. $from = $header->from[0]->mailbox . "@" . $header->from[0]->host;
  22. $toaddress = $header->toaddress;
  23. echo '<strong>To:</strong> ' . $toaddress . '<br>';
  24. echo '<strong>From:</strong> ' . $from . '<br>';
  25. $message = quoted_printable_decode(imap_fetchbody($inbox,$email_number,1.1));
  26. if ($message == '') {
  27. $message = (imap_fetchbody($inbox, $email_number, 1));
  28. echo '<strong>Body:</strong> ' . $message . '<br>';
  29. echo '<br>';
  30. }
  31. }
  32. }
  33. imap_expunge($inbox);
  34. imap_close($inbox);
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement