PHP code example of vasim-seta / codeigniter-imap
1. Go to this page and download the library: Download vasim-seta/codeigniter-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/ */
vasim-seta / codeigniter-imap example snippets shell
sudo apt-get install php*-imap && sudo apache2ctl graceful
php
$oClient = new \Vasim\IMAP\Client([
'host' => 'somehost.com',
'port' => 993,
'encryption' => 'ssl',
'validate_cert' => true,
'username' => 'username',
'password' => 'password',
]);
//Connect to the IMAP Server
$oClient->connect();
//Get all Mailboxes
/** @var \Vasim\IMAP\Support\FolderCollection $aFolder */
$aFolder = $oClient->getFolders();
//Loop through every Mailbox
/** @var \Vasim\IMAP\Folder $oFolder */
foreach($aFolder as $oFolder){
//Get all Messages of the current Mailbox $oFolder
/** @var \Vasim\IMAP\Support\MessageCollection $aMessage */
$aMessage = $oFolder->getMessages();
/** @var \Vasim\IMAP\Message $oMessage */
foreach($aMessage as $oMessage){
echo $oMessage->subject.'<br />';
echo 'Attachments: '.$oMessage->getAttachments()->count().'<br />';
echo $oMessage->getHTMLBody(true);
//Move the current Message to 'INBOX.read'
if($oMessage->moveToFolder('INBOX.read') == true){
echo 'Message has ben moved';
}else{
echo 'Message could not be moved';
}
}
}
php
/** @var \Vasim\IMAP\Client $oClient */
/** @var \Vasim\IMAP\Folder $oFolder */
$oFolder = $oClient->getFolder('INBOX.name');
php
/** @var \Vasim\IMAP\Folder $oFolder */
/** @var \Vasim\IMAP\Message $oMessage */
$oMessage = $oFolder->getMessage($uid = 1);
php
/** @var \Vasim\IMAP\Message $oMessage */
$oMessage->setFlag(['Seen', 'Spam']);
$oMessage->unsetFlag('Spam');
php
/** @var \Vasim\IMAP\Message $oMessage */
/** @var \Vasim\IMAP\Support\AttachmentCollection $aAttachment */
$aAttachment = $oMessage->getAttachments();
$aAttachment->each(function ($oAttachment) {
/** @var \Vasim\IMAP\Attachment $oAttachment */
$oAttachment->save();
});
php
/** @var \Vasim\IMAP\Folder $oFolder */
/** @var \Vasim\IMAP\Support\MessageCollection $aMessage */
$aMessage = $oFolder->searchMessages([['TEXT', 'Hello world']], null, false);
/** @var \Vasim\IMAP\Support\MessageCollection $aMessage */
$aMessage = $oFolder->getMessages('ALL', null, false);
php
/** @var \Vasim\IMAP\Folder $oFolder */
/** @var \Vasim\IMAP\Support\MessageCollection $aMessage */
$aMessage = $oFolder->searchMessages([['TEXT', 'Hello world']], null, false, 'UTF-8', false);
/** @var \Vasim\IMAP\Support\MessageCollection $aMessage */
$aMessage = $oFolder->getMessages('ALL', null, false, false);
php
$oFolder = $aMessage->getContainingFolder();