Skip to content

Instantly share code, notes, and snippets.

@thecrypticace
Created March 8, 2018 00:08
Show Gist options
  • 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("[email protected]", "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