PHP code example of sendkit / sendkit-php

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

    

sendkit / sendkit-php example snippets


use SendKit\SendKit;

$client = SendKit::client('your-api-key');

$response = $client->emails()->send([
    'from' => '[email protected]',
    'to' => '[email protected]',
    'subject' => 'Hello from SendKit',
    'html' => '<h1>Welcome!</h1>',
]);

echo $response['id']; // Email ID

$response = $client->emails()->sendMime(
    envelopeFrom: '[email protected]',
    envelopeTo: '[email protected]',
    rawMessage: $mimeString,
);

echo $response['id'];

$contact = $client->contacts()->create([
    'email' => '[email protected]',
    'first_name' => 'John',
    'last_name' => 'Doe',
    'unsubscribed' => false,
    'list_ids' => ['list-uuid-1', 'list-uuid-2'],
    'properties' => ['COMPANY' => 'Acme'],
]);

echo $contact['id'];

$contacts = $client->contacts()->list();
$contacts = $client->contacts()->list(['page' => 2]);

$contacts['data'];           // array of contacts
$contacts['meta']['total'];  // total count

$contact = $client->contacts()->get('contact-uuid');

$contact = $client->contacts()->update('contact-uuid', [
    'first_name' => 'Johnny',
    'unsubscribed' => true,
]);

$client->contacts()->delete('contact-uuid');

$contact = $client->contacts()->addToLists('contact-uuid', ['list-uuid-1', 'list-uuid-2']);

$lists = $client->contacts()->listLists('contact-uuid');
$lists = $client->contacts()->listLists('contact-uuid', ['page' => 2]);

$client->contacts()->removeFromList('contact-uuid', 'list-uuid');

$property = $client->contactProperties()->create([
    'key' => 'company',
    'type' => 'string',           // "string", "number", or "date"
    'fallback_value' => 'N/A',    // optional
]);

echo $property['id'];

$properties = $client->contactProperties()->list();
$properties = $client->contactProperties()->list(['page' => 2]);

$property = $client->contactProperties()->update('property-uuid', [
    'key' => 'organization',
    'fallback_value' => 'Unknown',
]);

$client->contactProperties()->delete('property-uuid');

$result = $client->validateEmail('[email protected]');

$result['is_valid'];       // "HIGH" or "LOW"
$result['should_block'];   // true if the email should be blocked
$result['block_reason'];   // reason for blocking, or null
$result['evaluations'];    // detailed evaluation results

use SendKit\Exceptions\SendKitException;

try {
    $client->emails()->send([...]);
} catch (SendKitException $e) {
    echo $e->getMessage(); // Error message
    echo $e->status;       // HTTP status code
}
bash
composer