Skip to content

Instantly share code, notes, and snippets.

@thecrypticace
Created March 8, 2018 00:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thecrypticace/fe46f353d8f7bf6481b1396c8e1865d9 to your computer and use it in GitHub Desktop.
Save thecrypticace/fe46f353d8f7bf6481b1396c8e1865d9 to your computer and use it in GitHub Desktop.
Sample IMAP Code
<?php
use Fetch\Server;
// https://github.com/tedious/Fetch
$server = new Server("outlook.office365.com", 993);
$server->setAuthentication("myemail@domain.com", "mypassword");
$server->setFlag("novalidate-cert");
$server->setParam("DISABLE_AUTHENTICATOR", ["PLAIN"]);
foreach ($server->getMessages() as $message) {
$subject = $message->getSubject();
$sender = $message->getAddresses("from");
$textBody = $message->getMessageBody(false);
$htmlBody = $message->getMessageBody(true);
// Do something with the message
// …
// Delete it
$message->delete();
}
// Remove deleted messages
$server->expunge();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment