PHP code example of razzbee / php-libimap

1. Go to this page and download the library: Download razzbee/php-libimap 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/ */

    

razzbee / php-libimap example snippets


$imap = new \PHPLibImap\IMAP;

$imap->connectServer([
   'host' => 'localhost',
   'port' => 993,
   'imap_username' => '[email protected]',
   'password' => 'secret',
   'mailbox_name' => 'INBOX',
   'enableSSL' => true,
]);

$imap-> switchMailBox('mailbox_name');

$mailBoxes = $imap->getMailBoxes($pattern);

$mailBoxInfo = $imap->getMailBoxInfo($mailboxName=null,$forceNew=false);

$totalRecent = $imap->getMailBoxInfo()->recent;

$totalMsgNo = $imap->getTotalMessages();

//or

$totalMsgNo = $imap->getMailBoxInfo()->messages;

$mails = $imap->fetchMailBoxItems("mailbox_name")
              ->select(uid1,uid2,uid3,uid4...uidN)
			  ->getResults();

$mails = $imap->fetchMailBoxItems("mailbox_name")
              ->range(1,10)
			  ->orderById('desc')
			  ->getResults();

$mails = $imap->fetchMailBoxItems("mailbox_name")
              ->limit(1,10)
			  ->orderById('desc')
			  ->getResults();

$move = $imap->moveMail($mails_uids_array,$source_mailbox,$destination_mailbox,$expunge=false);
 
$setFlag = $imap->setFlag($mails_uids_array,$flag,$mailBoxName);
 
        $keyword = "hello";
		 
        //body must contain at least one occurrance of the keyword
        $searchCritiria['BODY'] = $keyword;
		
        //subject too must contain at least one occurrance of the keyword 
        $searchCritiria['SUBJECT'] = $keyword;
		
		$mailBoxName = "INBOX";
		
        $searchResults = $imap
            ->search($searchCritiria,$mailBoxName)
            ->limit(20)
            ->getResults();
json
"razzbee/php-libimap" : "dev-master"