PHP code example of horde / imap-client

1. Go to this page and download the library: Download horde/imap-client 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/ */

    

horde / imap-client example snippets


use Horde\Imap\Client\ConnectionConfig;
use Horde\Imap\Client\ImapClient;
use Horde\Imap\Client\ImapFetchQuery;
use Horde\Imap\Client\OpenMode;
use Horde\Imap\Client\SecureMode;
use Horde\Sasl\Credentials\PasswordCredentials;
use Horde\Sasl\Credentials\PlainSecret;

$client = new ImapClient(
    new ConnectionConfig(hostspec: 'imap.example.com', port: 993, secure: SecureMode::Ssl),
    new PasswordCredentials('alice', new PlainSecret('secret')),
);

$client->login();
$client->openMailbox('INBOX', OpenMode::Readonly);

$query = (new ImapFetchQuery())->envelope()->flags();
foreach ($client->fetch('INBOX', $client->getIdsOb('1:*'), $query) as $uid => $msg) {
    echo $uid . ': ' . $msg->getEnvelope()->subject . "\n";
}

$client->logout();