Imap

Configuration & usage

PHP IMAP Mailbox is a powerful and open source library to connect to a mailbox by POP3, IMAP and NNTP using the PHP IMAP extension. This library allows you to fetch emails from your email server. Extend the functionality or create powerful web applications to handle your incoming emails.

Installation

We will use the php-imap/php-imap package. You can install it this way:

composer require php-imap/php-imap

Requirements

These are the required php extension to use this package.

  • fileinfo

  • iconv

  • imap

  • mbstring

  • json

Configurations

Crypt Settings

You can define the JWT signer, algorithm and content type.

# IMAP server and mailbox folder
IMAP_PATH= 
    
# Username for the before configured mailbox
IMAP_LOGIN= 
    
# Password for the before configured username
IMAP_PASSWORD= 
    
# Server encoding (optional)        
IMAP_ATTACHMENTS_DIR= 
    
# Directory, where attachments will be saved (optional)
IMAP_SERVER_ENCODING='UTF-8'

# Trim leading/ending whitespaces of IMAP path (optional)
IMAP_TRIM_IMAP_PATH=true
    
# Attachment filename mode (optional; false = random filename; true = original filename)
IMAP_ATTACHMENT_FILENAME_MODE=false

Usage

// if the class is aware of injections
$imap = $this->imap;

// if the container is present
$imap = $this->di->get('imap');

// to access the shared db service
$imap = Di::getDefault()->get('imap');

Sources

Last updated