PHP code example of oxemis / oxibounce

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

    

oxemis / oxibounce example snippets



use \Oxemis\OxiBounce\OxiBounceClient;

// getenv will allow us to get the OXIBOUNCE_API_LOGIN/OXIBOUNCE_API_PWD variables we created before:

$apilogin = getenv('OXIBOUNCE_API_LOGIN');
$apipwd = getenv('OXIBOUNCE_API_PWD');

$oxibounce = new OxiBounceClient($apilogin, $apipwd);

// or, without using environment variables:

$apilogin = 'your API login';
$apipwd = 'your API password';

$oxibounce = new OxiBounceClient($apilogin, $apipwd);


use \Oxemis\OxiBounce\OxiBounceClient;

$client = new OxiBounceClient(API_LOGIN,API_PWD);
$user = $client->userAPI->getUser();

echo "Account :" . $user->getEmail() . "\n" .
     "Remaining credits : " . $user->getCredits() . "\n";


use Oxemis\OxiBounce\OxiBounceClient;
use Oxemis\OxiBounce\Objects\EmailCheck;
use Oxemis\OxiBounce\Objects\EmailCheckResult;  

// Create the Client
$apilogin = 'your API login';
$apipwd = 'your API password';
$client = new OxiBounceClient($apilogin, $apipwd);

// Run the check
// You can specify multiple addresses separated with a ";" (up to 50)
// You will have to keep the returned array (one element by email tested) to get results.
$tests = $client->checkAPI->runCheckAsync("[email protected]");

// We'll have to check that all tests are carried out.
// Remember that tests can take minutes !
// Other option is to use the synchronous method (which handle a timeout), see next chapter !
$pending = true;
while ($pending) {

    // $tests is the array returned by runCheckAsync()
    $results = $client->checkAPI->getCheckResultAsync($tests);
    
    // Will be set to true below if some tests are still "PENDING"
    $pending = false;
    
    // Wait for results
    foreach ($results as $result) {
        if ($result->getStatus() == EmailCheck::STATUS_PENDING) 
            // Some tests are still pending
            $pending = true;
            // Waiting for 1 second
            sleep(1);
        }        
    }
    
} 

// Use the results
foreach ($results as $result) {
    switch ($result->getResult()) {
        case EmailCheckResult::RESULT_OK:
            // The address is valid.
            echo $result->getEmail() . " is valid !";
            break;
        case EmailCheckResult::RESULT_KO:
            // The address is invalid.
            echo $result->getEmail() . " is invalid !";
            break;
        case EmailCheckResult::RESULT_NOTSURE:
            // The tests did not reveal whether the address is valid or not.
            // Other properties ($result->isRisky() for example) can give you more
            // information to let you decide whether or not to authorize the address.
            echo $result->getEmail() . " is not sure !";
            break;
    }
}


use Oxemis\OxiBounce\OxiBounceClient;
use Oxemis\OxiBounce\Objects\EmailCheck;
use Oxemis\OxiBounce\Objects\EmailCheckResult;  

// Create the Client
$apilogin = 'your API login';
$apipwd = 'your API password';
$client = new OxiBounceClient($apilogin, $apipwd);

// Run the check
// You can specify multiple addresses separated with a ";" (up to 50)
// The second parameter is the time out (in seconds).
$results = $client->checkAPI->checkEmails("[email protected]", 10);

// Use the results
foreach ($results as $result) {
    if ($result->getStatus() == EmailCheckResult::STATUS_DONE) {
        // The test is done, use object properties
        switch ($result->getResult()) {
            case EmailCheckResult::RESULT_OK:
                // The address is valid.
                echo $result->getEmail() . " is valid !";
                break;
            case EmailCheckResult::RESULT_KO:
                // The address is invalid.
                echo $result->getEmail() . " is invalid !";
                break;
            case EmailCheckResult::RESULT_NOTSURE:
                // The tests did not reveal whether the address is valid or not.
                // Other properties ($result->isRisky() for example) can give you more
                // information to let you decide whether or not to authorize the address.
                echo $result->getEmail() . " is not sure !";
                break;
        }
    } else {
        // This test is not finished (but timeout is reached) 
        echo $result->getEmail() . " the test is still 'PENDING'.";
    }
}


use Oxemis\OxiBounce\OxiBounceClient;
use Oxemis\OxiBounce\Objects\EmailList;  

// Create the Client
$apilogin = 'your API login';
$apipwd = 'your API password';
$client = new OxiBounceClient($apilogin, $apipwd);

// Upload a JSON file as a list
$list = $client->listAPI->addList("./test.json");

// Store the list ID to interact with
echo 'List uploaded as #' . $list->getId();

// Start the list analysis
$client->listAPI->startList($list->getId());

// Get refreshed information about the list 
$list = $client->listAPI->getList($list->getId());
echo "List is : " . $list->getStatus(); // PENDING, DONE, CANCELED

// Get results for list
$result = $client->listAPI->getListResults($list->getId());
foreach ($result as $emailCheckResult) {
    echo $emailCheckResult->getEmail() . " : " . $emailCheckResult->getResult() . "\n";
}

// Delete the list
$client->listAPI->deleteList($list->getId());