1. Go to this page and download the library: Download seedgabo/laravel-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/ */
php
use Webklex\IMAP\Client;
$oClient = new Client([
'host' => 'somehost.com',
'port' => 993,
'encryption' => 'ssl',
'validate_cert' => true,
'username' => 'username',
'password' => 'password',
'protocol' => 'imap'
]);
/* Alternative by using the Facade
$oClient = Webklex\IMAP\Facades\Client::account('default');
*/
//Connect to the IMAP Server
$oClient->connect();
//Get all Mailboxes
/** @var \Webklex\IMAP\Support\FolderCollection $aFolder */
$aFolder = $oClient->getFolders();
//Loop through every Mailbox
/** @var \Webklex\IMAP\Folder $oFolder */
foreach($aFolder as $oFolder){
//Get all Messages of the current Mailbox $oFolder
/** @var \Webklex\IMAP\Support\MessageCollection $aMessage */
$aMessage = $oFolder->messages()->all()->get();
/** @var \Webklex\IMAP\Message $oMessage */
foreach($aMessage as $oMessage){
echo $oMessage->getSubject().'<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
// Folder::search() is just an alias for Folder::query()
/** @var \Webklex\IMAP\Support\MessageCollection $aMessage */
$aMessage = $oFolder->search()->text('hello world')->since('15.03.2018')->get();
// Folder::messages() is just an alias for Folder::query()
/** @var \Webklex\IMAP\Support\MessageCollection $aMessage */
$aMessage = $oFolder->messages()->text('hello world')->since('15.03.2018')->get();
php
/** @var \Webklex\IMAP\Folder $oFolder */
//Get all messages for page 2 since march 15 2018 where each apge contains 10 messages
/** @var \Webklex\IMAP\Support\MessageCollection $aMessage */
$aMessage = $oFolder->query()->since('15.03.2018')->limit(10, 2)->get();
php
/** @var \Webklex\IMAP\Message $oMessage */
class CustomMessageMask extends \Webklex\IMAP\Support\Masks\MessageMask {
/**
* New custom method which can be called through a mask
* @return string
*/
public function token(){
return implode('-', [$this->message_id, $this->uid, $this->message_no]);
}
}
$mask = $oMessage->mask(CustomMessageMask::class);
echo $mask->token().'@'.$mask->uid;
php
$oFolder = $aMessage->getContainingFolder();
php
echo 'your php code...';
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.