1. Go to this page and download the library: Download johnnymast/mailreader 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/ */
johnnymast / mailreader example snippets
use JM\MailReader\MailReader;
try {
$reader = new MailReader();
$reader->connect([
'server' => 'foobar.com',
'username' => '[email protected]',
'password' => 'bar'
]);
/**
* Note: Uncomment the following line if
* you wish to read a mailbox (folder)
*/
//$reader->setMailbox('Sent');
// messages will now contain the emails you received
$messages = $reader->readMailbox();
if (is_array($messages) && count($messages) > 0) {
foreach($messages as $email) {
$header = $email['header'];
// Assuming CLI here
print $header->Subject."\n";
}
}
} catch (\Exception $e) {
print $e->getMessage();
}
use JM\MailReader\MailReader;
try {
$reader = new MailReader();
$reader->connect([
'server' => 'foobar.com',
'username' => '[email protected]',
'password' => 'bar'
]);
/**
* Note: Uncomment the following line if
* you wish to read a mailbox (folder)
*/
//$reader->setMailbox('Sent');
// messages will now contain the emails you received
$messages = $reader->readMailbox();
if (is_array($messages) && count($messages) > 0) {
foreach($messages as $email) {
$header = $email['header'];
// Assuming CLI here
print $header->Subject."\n";
}
}
} catch (\Exception $e) {
print $e->getMessage();
}
use JM\MailReader\MailReader;
/**
* Note: port is an additional option to set.
* This option is not '
]);
$mailbox = 'Unread';
$targetEmailAddress = '[email protected]';
// Create the mailbox (folder) if it does not already exist.
if ($reader->mailboxExists($mailbox) == false) {
$reader->createMailbox($mailbox);
$reader->subscribeMailbox($mailbox);
}
$messages = $reader->filterUnReadMessagesTo($targetEmailAddress);
if (is_array($messages) && count($messages) > 0) {
foreach($messages as $message) {
$reader->moveMessage($message['index'], $mailbox);
}
}
// Switch to mailbox (folder) $mailbox
$reader->setMailbox('unseen');
// Retrieve the messages in mailbox (folder) $mailbox
$reader->setMailbox($mailbox);
$messages = $reader->readMailbox();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.