{"id":26698751,"url":"https://github.com/benhall14/php-imap-reader","last_synced_at":"2025-07-09T05:33:36.966Z","repository":{"id":19383383,"uuid":"86737916","full_name":"benhall14/php-imap-reader","owner":"benhall14","description":"A PHP class that makes working with IMAP in PHP as easy as possible.","archived":false,"fork":false,"pushed_at":"2024-08-15T22:13:31.000Z","size":40,"stargazers_count":31,"open_issues_count":0,"forks_count":11,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-26T22:19:02.445Z","etag":null,"topics":["imap","imap-client","php"],"latest_commit_sha":null,"homepage":"https://conobe.co.uk/projects/php-imap-reader","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/benhall14.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-03-30T18:55:53.000Z","updated_at":"2024-12-30T09:15:06.000Z","dependencies_parsed_at":"2024-05-19T20:49:14.239Z","dependency_job_id":null,"html_url":"https://github.com/benhall14/php-imap-reader","commit_stats":{"total_commits":31,"total_committers":4,"mean_commits":7.75,"dds":0.4193548387096774,"last_synced_commit":"d01afc74a3d8bb75c7de8fd75d56b3a116c3a2de"},"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benhall14%2Fphp-imap-reader","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benhall14%2Fphp-imap-reader/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benhall14%2Fphp-imap-reader/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benhall14%2Fphp-imap-reader/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/benhall14","download_url":"https://codeload.github.com/benhall14/php-imap-reader/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248670507,"owners_count":21142897,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["imap","imap-client","php"],"created_at":"2025-03-26T22:19:12.803Z","updated_at":"2025-04-13T05:39:44.475Z","avatar_url":"https://github.com/benhall14.png","language":"PHP","funding_links":["https://paypal.me/benhall14"],"categories":[],"sub_categories":[],"readme":"# PHP IMAP Reader\nA PHP class that makes working with IMAP as easy as possible. \n\nThis class is written to be chain-able so to create a logically fluent and easily readable way to access an IMAP mailbox. \n\nIt simplifies the PHP IMAP_* library into a set of easy to read methods that do the heavy lifting for you.\n\nIt has been fully tested to work with PHP 5.3+, including **PHP 8.1.**\n\n# Installation via Composer\nYou can now install this class via composer.\n\n\t$ composer require benhall14/php-imap-reader\n\t\n**Remember** to add the composer autoloader before using the class and use the correct namespace.\n\n\trequire 'vendor/autoload.php';\n\n\tuse benhall14\\phpImapReader\\Email as Email;\n\tuse benhall14\\phpImapReader\\EmailAttachment as EmailAttachment;\n\tuse benhall14\\phpImapReader\\Reader as Reader;\n\n# Usage\nPlease make sure you have added the required classes.\n\nIn its simplest form, use the following to connect:\n\n```php\ndefine('IMAP_USERNAME', ''); \t\t\t\t# your imap user name\ndefine('IMAP_PASSWORD', ''); \t\t\t\t# your imap password\ndefine('IMAP_MAILBOX', ''); \t\t\t\t# your imap address EG. {mail.example.com:993/novalidate-cert/ssl}\ndefine('ATTACHMENT_PATH', __DIR__ . '/attachments'); \t# the path to save attachments to or false to skip attachments\n\ntry{\n    \n    # set the mark as read flag (true by default). If you don't want emails to be marked as read/seen, set this to false.\n    $mark_as_read = true;\n\n    # You can ommit this to use UTF-8 by default.\n    $encoding = 'UTF-8'\n\n    # create a new Reader object\n    $imap = new Reader(IMAP_MAILBOX, IMAP_USERNAME, IMAP_PASSWORD, ATTACHMENT_PATH, $mark_as_read, $encoding);\n\n    # use one or more of the following chain-able methods to filter your email selection\n    $imap\n        -\u003efolder($folder)           # alias for mailbox($mailbox)\n        -\u003emailbox($mailbox)         # sets the mailbox to return emails from. Default = INBOX\n        -\u003eid($id)                   # retrieve a specific email by id\n        -\u003erecent()                  # get all RECENT emails\n        -\u003eflagged()                 # get all FLAGGED emails\n        -\u003eunflagged()               # get all UNFLAGGED emails\n        -\u003eunanswered()              # get all UNANSWERED emails\n        -\u003edeleted()                 # get all DELETED emails\n        -\u003eunread() \t\t    # alias for UNSEEN()\n        -\u003eunseen()                  # get all UNSEEN emails\n        -\u003efrom($email)              # get all emails from $email\n        -\u003esearchSubject($string)    # get all emails with $string in the subject line\n        -\u003esearchBody($string)       # get all emails with $string in the body\n        -\u003esearchText($string)       # get all emails with $string TEXT\n        -\u003eseen()                    # get all SEEN emails\n        -\u003eread() \t\t    # alias for SEEN()\n        -\u003enewMessages()             # get all NEW emails\n        -\u003eoldMessages()             # get all OLD emails\n        -\u003ekeyword($keyword)         # get all emails with $keyword KEYWORD\n        -\u003eunkeyword($keyword)       # get all emails without $keyword KEYWORD\n        -\u003ebeforeDate($date)         # get all emails received before $date. *Date should be in a format that can be parsed by strtotime.*\n        -\u003esinceDate($date)          # get all emails received since $date. *Date should be in a format that can be parsed by strtotime.*\n        -\u003esentTo($to)               # get all emails sent to $to\n        -\u003esearchBCC($string)        # get all emails with $string in the BCC field\n        -\u003esearchCC($string)         # get all emails with $string in the CC field\n        -\u003eonDate($date)             # get all emails received on $date. *Date should be in a format that can be parsed by strtotime.*\n        -\u003elimit($limit)             # limit the number of emails returned to $limit for pagination\n        -\u003epage($page)               # used with limit to create pagination\n        -\u003eorderASC()                # order the emails returned in ASCending order\n        -\u003eorderDESC()               # order the emails returned in DESCendeing order\n        -\u003ereset()                   # resets the current reader to be able to reconnect to another folder/mailbox.\n        -\u003eall()                     # get all emails (default)\n        -\u003eget();                    # finally make the connection and retrieve the emails.\n    \n    # You can then loop through $imap-\u003eemails() for each email.\n    foreach($imap-\u003eemails() as $email){\n\n        # The email has been clean and formated.\n        # see below.\n\n    }\n\n    # Reset the reader and connect to another folder.\n    $imap-\u003ereset()-\u003efolder('Sent')-\u003eget();\n\n    # You can also create a folder/mailbox on the IMAP stream.\n    $imap-\u003ecreateFolder('New Folder Name');\n    #or \n    $imap-\u003ecreateMailbox('New Folder Name');\n\n    # You can also check if a mailbox/folder exists on the IMAP stream using:\n    if ($imap-\u003edoesMailboxExists('INBOX')) {\n        return \"Yes, it exsits\";\n    } else {\n        return \"No, it doesn't exist.\";\n    }\n    \n    # ... your code here ...\n\n} catch (Exception $e){\n\n    echo $e-\u003egetMessage();\n\n}\n```\n\nWhile looping through the returned emails, each email object can be used as below:\n```php\n\n    $email-\u003eisTo('mail@example.com');   # Return true if the email is to $email, else returns false\n\n    $email-\u003ereplyTo();              \t# Returns an array of Reply To email addresses (and names)\n\n    $email-\u003ecc();                 \t# Returns an array of CC email addresses (and names)\n\n    $email-\u003eto();                       # Returns the recipient email address\n\n    $email-\u003eid();                       # Returns the id of the email\n\n    $email-\u003esize();                     # Returns the size of the email\n\n    $email-\u003edate($format);        \t# Returns the date in the $format specified. Default Y-m-d H:i:s\n\n    $email-\u003esubject();          \t# Returns the email subject\n\n    $email-\u003efromName();     \t\t# Returns the sender's name, if set.\n\n    $email-\u003efromEmail();     \t\t# Returns the sender's email address\n\n    $email-\u003eplain();            \t# Returns the plain text body of the email, if present\n\n    $email-\u003ehtml();            \t\t# Returns the html body of the email, if present\n\n    $email-\u003ehasAttachments();       \t# Returns true/false based on if the email has attachments\n\n    $email-\u003eattachments();      \t# Returns an array of EmailAttachment objects\n\n    $email-\u003eattachment($id);    \t# Returns an attachment based on the given attachment $id\n\n    $email-\u003eisRecent();   \t\t# Returns true/false based on the recent flag\n\n    $email-\u003eisUnseen();       \t\t# Returns true/false based on the unseen flag\n\n    $email-\u003eisFlagged();  \t\t# Returns true/false based on the flagged flag\n\n    $email-\u003eisAnswered(); \t\t# Returns true/false based on the answered flag\n\n    $email-\u003eisDeleted();      \t\t# Returns true/false based on the deleted flag\n\n    $email-\u003eisDraft();          \t# Returns true/false based on the draft flag\n\n    $email-\u003eeml();                      # Returns the email in .eml format\n\n    $email-\u003esaveEml($filename);         # Saves the email in .eml format\n    \n    $email-\u003ecount();         # Returns number of emails in folder\n\n```\n\nThe **$email-\u003eattachments();** method returns an array of attachments belonging to the email in a **benhall14\\phpImapReader\\EmailAttachment** object. The following methods are available for each attachment.\n\n```php\n\n\t# check if the current $email has any attachments.\n\tif($email-\u003ehasAttachments()){\n\t\n\t\t# get the attachments for the current $email in the\tloop.\n\t\t$attachments = $email-\u003eattachments();\n\t\n\t\t# loop through the found attachments.\n\t\tforeach($attachments as $attachment){\n\n\t\t\t$attachment-\u003eid(); \t\t\t# Returns the attachments ID.\n\n\t\t\t$attachment-\u003ename(); \t\t    \t# Returns the attachments name.\n\n\t\t\t$attachment-\u003efilePath(); \t\t# Returns the local file path for the attachment. This is based on the ATTACHMENT_PATH constant set in the imap config.\n\n\t\t\t$attachment-\u003econtent();\t\t\t# Returns the attachments content data.\n\n\t\t\t$attachment-\u003etype(); \t\t\t# Returns either 'attachment' or 'inline'.\n\n\t\t}\n\n}\t\n```\n\n# Requirements\n\n**Works with PHP 5.3+ (including PHP 8.1)**\n\n**PHP IMAP Extension**\n\n# License\nCopyright (c) 2016-2021 Benjamin Hall, ben@conobe.co.uk\nhttps://conobe.co.uk\n\nLicensed under the MIT license\n\n# Donate?\n\nIf you find this project helpful or useful in anyway, please consider getting me a cup of coffee - It's really appreciated :)\n\n[![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://paypal.me/benhall14)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbenhall14%2Fphp-imap-reader","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbenhall14%2Fphp-imap-reader","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbenhall14%2Fphp-imap-reader/lists"}