PHP code example of truehero / getnada-api

1. Go to this page and download the library: Download truehero/getnada-api 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/ */

    

truehero / getnada-api example snippets


 
ruehero\Getnada;

$getnada = new Getnada();

$api_version = 1;
$client = new \Truehero\CommonClient($api_version);
//$client->setUserAgent('Custom UA');
//$client->setHeaders(['Custom-Header' => 'Custom Header Value']);
//$client->setProxy('121.100.26.6');

$getnada = new Getnada($client);

$domains = $getnada->domains();

foreach ($domains as $domain) {
    echo 'Name: ' . $domain->getName();
    echo 'ID: ' . $domain->getId();
}

$email = '[email protected]';
$box = $getnada->inbox($email);

foreach($box as $message) {
    echo 'ID: ' . $message->getId();
    echo 'From: ' . $message->getFrom();
    echo 'To: ' . $message->getTo();
    echo 'Date: ' . $message->getDate()->format('d-m-Y H:i:s');
    // echo $message->getDate()->getDate(); - date with default format
    echo 'Message: ' . $message->getMessage();
}

// directory, where we want to save attaches
$saveDir = __DIR__ . '/storage';

foreach($box as $message) {
   echo 'ID: ' . $message->getId();
   // ...
   echo 'Message: ' . $message->getMessage();

   // Check, if message has attaches
   if($message->hasAttaches()) {
       foreach($message->getAttaches() as $attach) {
           $file = $getnada->downloadFile($message, $attach, $saveDir);

           echo 'File was saved by path: ' . $file;
           
           echo 'Name: ' . $attach->getName();
           echo 'ID: ' . $attach->getId();
           echo 'Type: ' . $attach->getType();
           echo 'Size: ' . $attach->getSize()->format();
           echo 'Total Attaches: ' . $message->countAttaches();
       }
   }
}

$email = $getnada->randomEmail($getnada->domains());
$box = $getnada->inbox($email);
// ...

if($getnada->hasNew($email)) {
    // mailbox has new unread messages   
}