Coder Social home page Coder Social logo

imap's Introduction

IMAP Library for PHP

Downloads this Month Tests Latest Stable Version License

This IMAP Library for PHP provides an intuitive and easy-to-use interface to interact with POP3, IMAP and NNTP mail servers. It allows for operations such as connecting to mailboxes, fetching messages, handling message parts, and managing email content.

  • Connect to IMAP servers with ease
  • Fetch and manage email messages
  • Handle different parts of an email such as attachments and text
  • Decode email content and headers
  • Supports message deletion and structure analysis

Installation

To install the library, you can use Composer. Run the following command in your project directory:

composer require dg/imap

It requires PHP version 8.1 with extension imap.

Connecting to a Mailbox

To connect to an IMAP mailbox, create an instance of the Mailbox class.

use DG\Imap\Mailbox;

$mailbox = new Mailbox(
	'{imap.gmail.com:993/imap/ssl}',
	'[email protected]',
	'your_password',
);

$mailbox->connect();

Fetching Messages

Fetch all messages from the mailbox:

$messages = $mailbox->getMessages();
foreach ($messages as $message) {
	echo $message->getSubject() . "\n";
}

Handling Message Parts

To handle different parts of a message, such as attachments:

foreach ($messages as $message) {
	$parts = $message->getParts();
	foreach ($parts as $part) {
		// Process each part
	}
}

Certainly, here's the additional information regarding error handling through exceptions:

Error Handling

In case of any issue, such as a failure to connect to the IMAP server, fetch messages, or process message parts, the library will throw an DG\Imap\Exception:

try {
    $mailbox->connect();
    $messages = $mailbox->getMessages();
    // ... additional operations
} catch (DG\Imap\Exception $e) {
    echo 'Error: ' . $e->getMessage();
}

Support Project

Do you like this project?

Donate

imap's People

Contributors

dg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.