Source Code View on GitHub
Install
composer require sendkit/sendkit-php
Send email
use SendKit\ SendKit ;
$client = SendKit :: client ( 'sk_your_api_key' );
$response = $client -> emails () -> send ([
'from' => 'Your Name <you@yourdomain.com>' ,
'to' => 'recipient@example.com' ,
'subject' => 'Hello from SendKit' ,
'html' => '<h1>Welcome!</h1><p>Your first email with SendKit.</p>' ,
]);
echo $response [ 'id' ];
Validate email
Validate an email address before sending. Each validation costs credits.
use SendKit\ SendKit ;
$client = SendKit :: client ( 'sk_your_api_key' );
$result = $client -> validateEmail ( 'recipient@example.com' );
if ( $result [ 'should_block' ]) {
// Email should not be used
echo $result [ 'block_reason' ];
}
echo $result [ 'is_valid' ]; // "HIGH" or "LOW"
echo $result [ 'evaluations' ]; // detailed checks
The evaluations array contains:
Key Description has_valid_syntaxWhether the email has valid syntax has_valid_dnsWhether the domain has valid DNS records mailbox_existsWhether the mailbox exists is_role_addressWhether it’s a role address (e.g. info@, admin@) is_disposableWhether it’s a disposable email is_random_inputWhether it appears to be random input
Create a new contact or update an existing one if the email already exists (upsert).
$contact = $client -> contacts () -> create ([
'email' => 'john@example.com' ,
'first_name' => 'John' ,
'last_name' => 'Doe' ,
'list_ids' => [ 'list-uuid-1' , 'list-uuid-2' ],
'properties' => [ 'COMPANY' => 'Acme' ],
]);
echo $contact [ 'id' ];
Retrieve a paginated list of contacts.
$contacts = $client -> contacts () -> list ();
// With pagination
$contacts = $client -> contacts () -> list ([ 'page' => 2 ]);
echo $contacts [ 'meta' ][ 'total' ]; // total contacts
$contact = $client -> contacts () -> get ( 'contact-uuid' );
echo $contact [ 'email' ];
echo $contact [ 'properties' ][ 'COMPANY' ];
$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' );
// With pagination
$lists = $client -> contacts () -> listLists ( 'contact-uuid' , [ 'page' => 2 ]);
$client -> contacts () -> removeFromList ( 'contact-uuid' , 'list-uuid' );
Contact properties let you define custom fields for your contacts.
Create a property
$property = $client -> contactProperties () -> create ([
'key' => 'company' ,
'type' => 'string' , // "string", "number", or "date"
'fallback_value' => 'N/A' , // optional
]);
echo $property [ 'id' ];
List properties
$properties = $client -> contactProperties () -> list ();
// With pagination
$properties = $client -> contactProperties () -> list ([ 'page' => 2 ]);
Update a property
$property = $client -> contactProperties () -> update ( 'property-uuid' , [
'key' => 'organization' ,
'fallback_value' => 'Unknown' ,
]);
Delete a property
$client -> contactProperties () -> delete ( 'property-uuid' );
A SendKitException with status 409 is thrown if the property is used in segment filters.