PHP code example of gricob / imap

1. Go to this page and download the library: Download gricob/imap library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

gricob / imap example snippets


$client = \Gricob\IMAP\Client::create(
    new \Gricob\IMAP\Configuration(
        transport: 'ssl',
        host: 'imap.example.com',
        port: 993,
        timeout: 60,
        verifyPeer: true,
        verifyPeerName: true,
        allowSelfSigned: false,
        useUid: true,
    )
);

$client->logIn('username', 'password');

// List available mailbox
$mailboxes = $client->mailboxes();

// Select an specific mailbox
$client->select($mailboxes[0]);

// Fetch message by sequence number or uid (depends on useUid configuration)
$message = $client->fetch(1);

// Or search messages by criteria
$messages = $client->search()
    ->since(new DateTime('yesterday'))
    ->not()->header('In-Reply-To'))
    ->get();