PHP code example of phps-cans / imapi
1. Go to this page and download the library: Download phps-cans/imapi 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/ */
phps-cans / imapi example snippets
$client = Imapi\Client::connect('imap.host.com', 'user', 'password');
$hordeClient = new Horde_Imap_Client_Socket([
'username' => $username,
'password' => $password,
'hostspec' => $host,
'port' => '143',
'secure' => 'tls',
]);
$client = new Imapi\Client($hordeClient);
$emails = $client->getEmails();
foreach ($emails as $email) {
echo $email->getSubject();
}
$ids = $client->getEmailIds();
foreach ($ids as $id) {
if (/* this email needs to be synced */) {
$email = $client->getEmailFromId($id);
// ...
}
}
// Read from the `INBOX.Sent` folder
$query = QueryBuilder::create('INBOX.Sent')
->youngerThan(3600) // 1 hour
->getQuery();
$emails = $client->getEmails($query);
$folders = $client->getFolders();
$emailIds = ['123', '456'];
// Moving from the INBOX to the Archive folder
$client->moveEmails($emailIds, 'INBOX', 'Archive');
$emailIds = ['123', '456'];
$client->deleteEmails($emailIds, 'Deleted Messages');