Advertisement
Guest User

Untitled

a guest
Dec 16th, 2016
501
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.45 KB | None | 0 0
  1. <?php
  2. set_time_limit(4000);
  3.  
  4. // Connect to gmail
  5. $imapPath = '{imap.gmail.com:993/imap/ssl}INBOX';
  6. $username = '<your-email>';
  7. $password = '<email-password>';
  8.  
  9. // try to connect
  10. $inbox = imap_open($imapPath,$username,$password) or die('Cannot connect to Gmail: ' . imap_last_error());
  11.  
  12. /* ALL - return all messages matching the rest of the criteria
  13. ANSWERED - match messages with the \\ANSWERED flag set
  14. BCC "string" - match messages with "string" in the Bcc: field
  15. BEFORE "date" - match messages with Date: before "date"
  16. BODY "string" - match messages with "string" in the body of the message
  17. CC "string" - match messages with "string" in the Cc: field
  18. DELETED - match deleted messages
  19. FLAGGED - match messages with the \\FLAGGED (sometimes referred to as Important or Urgent) flag set
  20. FROM "string" - match messages with "string" in the From: field
  21. KEYWORD "string" - match messages with "string" as a keyword
  22. NEW - match new messages
  23. OLD - match old messages
  24. ON "date" - match messages with Date: matching "date"
  25. RECENT - match messages with the \\RECENT flag set
  26. SEEN - match messages that have been read (the \\SEEN flag is set)
  27. SINCE "date" - match messages with Date: after "date"
  28. SUBJECT "string" - match messages with "string" in the Subject:
  29. TEXT "string" - match messages with text "string"
  30. TO "string" - match messages with "string" in the To:
  31. UNANSWERED - match messages that have not been answered
  32. UNDELETED - match messages that are not deleted
  33. UNFLAGGED - match messages that are not flagged
  34. UNKEYWORD "string" - match messages that do not have the keyword "string"
  35. UNSEEN - match messages which have not been read yet*/
  36.  
  37. // search and get unseen emails, function will return email ids
  38. $emails = imap_search($inbox,'SUBJECT "For Imap:"');
  39.  
  40. $output = '';
  41. foreach($emails as $mail) {
  42. var_dump($mail);
  43. $headerInfo = imap_headerinfo($inbox,$mail);
  44. $output .= $headerInfo->subject.'<br/>';
  45. $output .= $headerInfo->toaddress.'<br/>';
  46. $output .= $headerInfo->date.'<br/>';
  47. $output .= $headerInfo->fromaddress.'<br/>';
  48. $output .= $headerInfo->reply_toaddress.'<br/>';
  49.  
  50. $emailStructure = imap_fetchstructure($inbox,$mail);
  51.  
  52. if(!isset($emailStructure->parts)) {
  53. $output .= imap_body($inbox, $mail, FT_PEEK);
  54. } else {
  55. //
  56. }
  57. echo $output;
  58. $output = '';
  59. }
  60.  
  61. // colse the connection
  62. imap_expunge($inbox);
  63. imap_close($inbox);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement