PHP code example of mattstein / unsend-php

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

    

mattstein / unsend-php example snippets


// Initialize via factory
$unsend = \Unsend\Unsend::create('your-api-key', 'https://app.unsend.dev');

// Send an email
$response = $unsend->sendEmail([
    'to' => '[email protected]',
    'from' => '[email protected]',
    'subject' => 'Library Test Email',
    'html' => '<p>This is a test!</p>',
    'text' => 'This is a test!'
]);

// Print email ID
echo $response->getData()->emailId;

$response = $unsend->getEmail('cxbkzjgku000xmw2tg7lndauk');

echo $response->getData()->subject;

$response = $unsend->listEmails([
    'domainId' => 3,
]);

foreach ($response->getData()->data as $email) {
    echo $email->subject . "\n";
}

foreach ($unsend->iterateEmails(['domainId' => 3]) as $email) {
    echo $email->subject . "\n";
}

$response = $unsend->sendEmail([
    'to' => '[email protected]',
    'from' => '[email protected]',
    'subject' => 'Library Test Email',
    'html' => '<p>This is a test!</p>',
    'text' => 'This is a test!'
]);

echo $response->getData()->emailId;

$response = $unsend->sendEmail([
    'to' => '[email protected]',
    'from' => '[email protected]',
    'subject' => 'Library Test Email',
    'html' => '<p>This is a test!</p>',
    'text' => 'This is a test!',
    'scheduledAt' => '2025-06-10T00:00:00Z'
]);

$scheduledEmailId = $response->getData()->emailId;

$unsend->updateSchedule($scheduledEmailId, '2025-06-07T00:00:00Z');

$unsend->cancelSchedule('cxbkzjgku000xmw2tg7lndauk');

$response = $unsend->getContact(
    'cxb19a523000foa3ctrd5h7u7',
    'cxb19bmdv000hoa3c3jfpx51t'
);

echo $response->getData()->email;

$response = $unsend->getContacts('cxb19a523000foa3ctrd5h7u7');

foreach ($response->getData() as $contact) {
    echo $contact->email . "\n";
}

$response = $unsend->createContact(
    'cxb19a523000foa3ctrd5h7u7',
    [
        'email' => '[email protected]',
        'firstName' => 'Tobias',
        'lastName' => 'Fünke',
        'subscribed' => true,
    ]
);

echo $response->getData()->contactId;

$unsend->updateContact(
    'cxb19a523000foa3ctrd5h7u7',
    'cxb19bmdv000hoa3c3jfpx51t',
    [
        'firstName' => 'Surely',
        'lastName' => 'Fünke',
    ]
);

$unsend->deleteContact('cxb19a523000foa3ctrd5h7u7', 'cxb19bmdv000hoa3c3jfpx51t');

$response = $unsend->getDomains();

foreach ($response->getData() as $domain) {
    echo $domain->name . "\n";
}

$response = $unsend->createDomain(
    [
        'name' => 'example.com',
        'region' => 'us-east-1',
    ]
);

echo $response->getData()->id;

$response = $unsend->verifyDomain(5);

echo $response->getData()->message;

composer