PHP code example of verifalia / sdk

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

    

verifalia / sdk example snippets


use Verifalia\VerifaliaRestClient;
use Verifalia\VerifaliaRestClientOptions;

$verifalia = new VerifaliaRestClient([
    VerifaliaRestClientOptions::USERNAME => 'your-username-here',
    VerifaliaRestClientOptions::PASSWORD => 'your-password-here'
]);

use Verifalia\VerifaliaRestClient;
use Verifalia\VerifaliaRestClientOptions;
use Verifalia\Security\BearerAuthenticationProvider;

$verifalia = new VerifaliaRestClient([
    VerifaliaRestClientOptions::AUTHENTICATION_PROVIDER => 
        new BearerAuthenticationProvider('your-username-here', 'your-password-here')
]);

use Verifalia\VerifaliaRestClient;
use Verifalia\VerifaliaRestClientOptions;

$verifalia = new VerifaliaRestClient([
    VerifaliaRestClientOptions::CERTIFICATE => '/home/gfring/Documents/pollos.pem'
]);

use Verifalia\VerifaliaRestClient;

$verifalia = new VerifaliaRestClient(...); // See above

// Verifies an email address

$job = $verifalia->emailValidations->submit('[email protected]');

// Print some results

$entry = $job->entries[0];

echo 'Classification: ' . $entry->classification;
echo 'Status: ' . $entry->status;

// Output:
// Classification: Deliverable
// Status: Success

use Verifalia\VerifaliaRestClient;

$verifalia = new VerifaliaRestClient(...); // See above

// Verifies an email address

$job = $verifalia->emailValidations->submit('bat[[email protected]');

// Print some results

$entry = $job->entries[0];

echo 'Classification: ' . $entry->classification . "\n";
echo 'Status: ' . $entry->status . "\n";
echo 'Syntax failure index: ' . $entry->syntaxFailureIndex . "\n";

if (!empty(entry->suggestions)) {
    echo "Suggestions\n";
    
    foreach ($entry->suggestions as $suggestion) {
        echo '- ' . $suggestion . "\n";
    }
}

// Output:
// Classification: Undeliverable
// Status: InvalidCharacterInSequence
// Syntax failure index: 3
// Suggestions:
// - [email protected]

use Verifalia\VerifaliaRestClient;

$verifalia = new VerifaliaRestClient(...); // See above

// Verifies the list of email addresses

$job = $verifalia->emailValidations->submit([
    '[email protected]',
    '[email protected]',
    '[email protected]',
]);

// Print some results

foreach ($job->entries as $entry) {
    echo $entry->emailAddress . ' => ' . $entry->classification;
}

// Output:
// [email protected] => Deliverable
// [email protected] => Undeliverable
// [email protected] => Deliverable

$job = $verifalia->emailValidations->submit(new FileValidationRequest('that-file.xlsx'));

$request = new FileValidationRequest('that-file.xlsx');
$request->sheet  3;
$request->startingRow = 1;
$request->column = 5;
$request->quality = QualityLevelName::HIGH;

$job = $verifalia->emailValidations->submit($request);

$stream = fopen('my-list.txt', 'rb');
$job = $verifalia->emailValidations->submit(new FileValidationRequest($stream, 'text/plain'));

$request = new ValidationRequest('[email protected]');
$request->quality = QualityLevelName::HIGH;

$job = $verifalia->emailValidations->submit($request);

$request = new ValidationRequest([
    '[email protected]',
    '[email protected]',
    '[email protected]',
]);
$request->deduplication = DeduplicationMode::RELAXED;

$job = $verifalia->emailValidations->submit($request);

$request = new ValidationRequest('[email protected]');
$request->retention = DateInterval::createFromDateString('10 minutes');

$job = $verifalia->emailValidations->submit($request);

$verifalia = new VerifaliaRestClient(...); // See above
$request = new ValidationRequest(...) // See above;

$job = $verifalia->emailValidations->submit($request, WaitOptions::$noWait);

echo 'Status: ' . $job->overview->status;

// Status: InProgress

use Verifalia\EmailValidations\ValidationOverview;
use Verifalia\EmailValidations\WaitOptions;

$verifalia = new VerifaliaRestClient(...); // See above
$request = new ValidationRequest(...) // See above;

$waitOptions = new WaitOptions(function (ValidationOverview $overview) {
    echo 'Job status: ' . $overview->status;
    
    if ($overview->progress !== null) {
        echo 'Progress: ' . $overview->progress->percentage . '%';
    }
});

$job = $verifalia->emailValidations->submit($request, $waitOptions);

$verifalia = new VerifaliaRestClient(...); // See above
$request = new ValidationRequest(...) // See above;

$request->completionCallback = new CompletionCallback('https://your-website-here/foo/bar');

$job = $verifalia->emailValidations->submit($request, $waitOptions);

$job = $verifalia->emailValidations->get('ec415ecd-0d0b-49c4-a5f0-f35c182e40ea');

// Exports the validated entries for the job in the CSV format

$export = $verifalia->emailValidations->exportEntries('722c2fd8-8837-449f-ad24-0330c597c993', ExportedEntriesFormat::CSV);

// Stores the binary string into a file

file_put_contents("my-list.csv", $export);

$verifalia->emailValidations->delete('ec415ecd-0d0b-49c4-a5f0-f35c182e40ea');

$balance = $verifalia
    ->credits
    ->getBalance();

echo 'Credit packs: ' . $balance->creditPacks . "\n";
echo 'Free daily credits: ' . $balance->freeCredits . "\n";
echo 'Free daily credits will reset in ' . $balance->freeCreditsResetIn . "\n";

// Prints out something like:
// Credit packs: 956.332
// Free daily credits: 128.66
// Free daily credits will reset in 09:08:23
bash
php composer.phar