1. Go to this page and download the library: Download mailkube/mailkube-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/ */
mailkube / mailkube-php example snippets
use Mailkube\Client;
$client = new Client(); // reads MAILKUBE_API_KEY
$email = $client->emails->send(
from: 'Acme <[email protected]>',
to: '[email protected]',
subject: 'Hello world',
html: '<p>It works!</p>',
);
echo $email->id, $email->messageId;
$client = new Client(httpClient: $myPsr18Client, requestFactory: $f, streamFactory: $f);
use Mailkube\ErrorName;
use Mailkube\Exception\RateLimitException;
try {
$client->emails->send(...);
} catch (RateLimitException $e) {
// $e->errorName === ErrorName::RateLimitExceeded->value
sleep($e->retryAfter ?? 1);
}
use Mailkube\Model\Tag;
$client->emails->send(
from: 'Acme <[email protected]>',
to: '[email protected]',
subject: 'Welcome',
html: '<p>Hi!</p>',
tags: [new Tag('campaign', 'launch'), new Tag('cohort', 'beta')],
);
$email = $client->emails->send(
from: 'Acme <[email protected]>',
to: '[email protected]',
subject: 'Your trial ends tomorrow',
html: '<p>Renew?</p>',
scheduledAt: new DateTimeImmutable('2026-08-20T07:00:00Z'),
batchId: 'trial-reminders', // optional label, only valid alongside scheduledAt
);
$client->scheduledEmails->batches->update('trial-reminders', '2026-08-22T07:00:00Z');
$result = $client->scheduledEmails->batches->cancel('trial-reminders');
echo $result->canceledCount; // an unknown batch is a no-op reporting 0, not an error
use Mailkube\Logging;
$client = new Client(logger: $myPsr3Logger);
$client = new Client(logger: Logging::errorLog('debug')); // no logging framework to hand
bash
composer
bash
composer
bash
MAILKUBE_LOG=debug php send.php
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.