PHP code example of opportify / opportify-sdk-php

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

    

opportify / opportify-sdk-php example snippets


use Opportify\Sdk\EmailInsights;

$emailInsights = new EmailInsights("YOUR-API-KEY-HERE");

$params = [
    "email" => "[email protected]", // *gmial* - just an example to be auto-corrected
    "enableAi" => true,
    "enableAutoCorrection" => true,
    "enableDomainEnrichment" => true // Optional: 

use Opportify\Sdk\IpInsights;

$ipInsights = new IpInsights("<YOUR-KEY-HERE>");

$params = [
    "ip" => "3.1.122.82",
    "enableAi" => true
];

$result = $ipInsights->analyze($params);

use Opportify\Sdk\FraudProtection;

$fraudProtection = new FraudProtection("<YOUR-KEY-HERE>");

$params = [
    // Identity
    "email"          => "[email protected]",
    "firstName"      => "Jane",
    "lastName"       => "Doe",
    "username"       => "jane_doe",
    "companyName"    => "Acme Corp",

    // Network
    "userIp"         => "3.1.122.82",

    // Contact details
    "phone1"         => "+1-800-555-0100",
    "website"        => "https://acme.example.com",

    // Submission context
    "subject"        => "Contact form submission",
    "message"        => "Hello, I am interested in your service.",
    "submissionType" => "contact",  // e.g. "contact", "signup", "checkout"
    "origin"         => "yoursite.com",  // hostname only — no protocol, path, or port

    // Address (all optional)
    "address1"       => "123 Main St",
    "city"           => "Springfield",
    "region"         => "IL",
    "country"        => "US",
    "postalCode"     => "62701",

    // Token & form tracking (optional)
    "opportifyToken"   => "opportify-generated-token",
    "opportifyFormUUID" => "uuid-of-the-form",

    // Raw form fields as key-value pairs (optional)
    "formData"       => ["custom_field" => "value"],
];

$result = $fraudProtection->analyze($params);
// $result->score    — integer 200–1000 (higher = riskier)
// $result->level    — "lowest" | "low" | "medium" | "high" | "highest"
// $result->factors  — string[] of detected risk signals
// $result->sources  — per-signal breakdown (email, IP, geo, session, velocity)

use Opportify\Sdk\EmailInsights;

$emailInsights = new EmailInsights("<YOUR-KEY-HERE>");

$params = [
    'emails' => [
        '[email protected]',
        '[email protected]'
    ],
    'name' => 'Customer Email Validation', // Optional: descriptive name for the job
    'enableAi' => true,
    'enableAutoCorrection' => true
];

// Default content type is application/json
$batch = $emailInsights->batchAnalyze($params);

// Optional: poll status later
$status = $emailInsights->getBatchStatus($batch->jobId);

$content = "[email protected]\[email protected]"; // newline-delimited emails
$batch = $emailInsights->batchAnalyze(['text' => $content], 'text/plain');
$status = $emailInsights->getBatchStatus($batch->jobId);

$batch = $emailInsights->batchAnalyzeFile(__DIR__.'/emails.csv', [
    'name' => 'Monthly Email Cleanup', // Optional: descriptive name for the job
    'enableAi' => true,
    'enableAutoCorrection' => true
]);
$status = $emailInsights->getBatchStatus($batch->jobId);

use Opportify\Sdk\IpInsights;

$ipInsights = new IpInsights("<YOUR-KEY-HERE>");

$params = [
    'ips' => [
        '1.1.1.1',
        '8.8.8.8'
    ],
    'name' => 'Network Security Scan', // Optional: descriptive name for the job
    'enableAi' => true
];

$batch = $ipInsights->batchAnalyze($params); // application/json
$status = $ipInsights->getBatchStatus($batch->jobId);

$content = "1.1.1.1\n8.8.8.8"; // newline-delimited IPs
$batch = $ipInsights->batchAnalyze(['text' => $content], 'text/plain');
$status = $ipInsights->getBatchStatus($batch->jobId);

$batch = $ipInsights->batchAnalyzeFile(__DIR__.'/ips.csv', [
    'name' => 'Firewall IP Assessment', // Optional: descriptive name for the job
    'enableAi' => true
]);
$status = $ipInsights->getBatchStatus($batch->jobId);

$emailInsights = new EmailInsights('<YOUR-KEY-HERE>');

// Trigger a new export for a completed batch job
$export = $emailInsights->createBatchExport('job-uuid-here', [
    'exportType' => 'csv',
    'columns' => [
        'emailAddress',
        'emailProvider',
        'riskReport.score',
        'isDeliverable'
    ],
    'filters' => [
        'isDeliverable' => 'true',
        'riskReport.score' => ['min' => 400]
    ]
]);

// Poll until the export is ready
$status = $emailInsights->getBatchExportStatus('job-uuid-here', $export->exportId);

if ($status->status === 'COMPLETED') {
    // Use $status->downloadUrl for the pre-signed file link
}

$ipInsights = new IpInsights('<YOUR-KEY-HERE>');

$export = $ipInsights->createBatchExport('job-uuid-here', [
    'exportType' => 'json',
    'columns' => [
        'result.ipAddress',
        'result.connectionType',
        'result.riskReport.score'
    ],
    'filters' => [
        'result.riskReport.level' => ['low', 'medium']
    ]
]);

$status = $ipInsights->getBatchExportStatus('job-uuid-here', $export->exportId);

if ($status->status === 'COMPLETED') {
    // Use $status->downloadUrl to retrieve the generated export
} elseif ($status->status === 'FAILED') {
    // Review $status->errorCode and $status->errorMessage for remediation guidance
}

$emailInsights->setDebugMode(true);
$ipInsights->setDebugMode(true);
$fraudProtection->setDebugMode(true);

$fraudProtection->setHost('https://staging.api.opportify.ai');
$fraudProtection->setVersion('v2');
$fraudProtection->setPrefix('intel');

use OpenAPI\Client\ApiException;

try {
    $result = $emailInsights->analyze($params);
    // or: $result = $ipInsights->analyze($params);
} catch (ApiException $e) {
    throw new \Exception($e->getResponseBody());
}

use OpenAPI\FraudIntel\Client\ApiException;

try {
    $result = $fraudProtection->analyze($params);
} catch (ApiException $e) {
    throw new \Exception($e->getResponseBody());
}
shell
composer