1. Go to this page and download the library: Download millionsend/millionsend-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/ */
// POST /emails/batch — up to 100 emails, one call
$ms->batch->send([$payloadA, $payloadB], [
'idempotency_key' => $key,
'batch_validation' => 'permissive', // or 'strict' (server default)
]);
$ms->contacts->create([
'email' => '[email protected]',
'first_name' => 'Ada',
'last_name' => 'Lovelace',
'unsubscribed' => false,
'properties' => ['plan' => 'pro'],
'segments' => [['id' => $segmentId]],
'topics' => [['id' => $topicId, 'subscription' => 'opt_in']],
]);
$ms->contacts->get('[email protected]'); // by id or email
$ms->contacts->update('[email protected]', ['first_name' => null, 'unsubscribed' => true]); // null clears
$ms->contacts->update(['id' => $id, 'last_name' => 'L']); // single-array shape also works
$ms->contacts->remove($id); // the contact's emails stay in the send log
$ms->contacts->remove($id, ['erase' => true]); // ?erase=true — also scrubs the address from email history, events and API logs (GDPR/LGPD)
$ms->contacts->list(['limit' => 50]);
$ms->contacts->list(['segment_id' => $segmentId]); // GET /segments/:id/contacts
// Bulk read (MillionSend extension): attach properties and topic subscriptions to every item,
// so an audience reads in one request per 100 contacts instead of one per contact
$ms->contacts->list(['limit' => 100, '422 when the instance cannot build hosted links (self-hosted without APP_BASE_URL)
// Segment membership
$ms->contacts->segments->add($idOrEmail, $segmentId); // POST /contacts/:id/segments/:segmentId
$ms->contacts->segments->remove($idOrEmail, $segmentId); // DELETE …
// Bulk create (MillionSend extension) — up to 1000 per call
$result = $ms->contacts->batch->create($contacts, [
'on_conflict' => 'upsert', // error (default) | skip | upsert
'batch_validation' => 'permissive', // strict (default) | permissive
]);
// $result['data'][] = ['index' => 0, 'id' => '…', 'status' => 'created'|'updated'|'skipped']
// $result['counts'] = ['created' => n, 'updated' => n, 'skipped' => n, 'failed' => n]
// $result['errors'][] = ['index' => 3, 'message' => '…'] (permissive mode)
// Bulk lookup (MillionSend extension) — up to 1000 contacts by id or email in one request,
// in request order; unknown entries are listed, not errors — one request against the rate limit
$result = $ms->contacts->batch->get([$contactId, ['email' => '[email protected]']], ['
$ms->contactProperties->create(['key' => 'plan', 'type' => 'string', 'fallback_value' => 'free']);
$ms->contactProperties->list();
$ms->contactProperties->get($id);
$ms->contactProperties->update($id, ['fallback_value' => null]); // only the fallback is mutable
$ms->contactProperties->remove($id);
$hook = $ms->webhooks->create([
'endpoint' => 'https://acme.dev/hooks/millionsend',
'events' => ['email.sent', 'email.delivered', 'email.bounced'],
'signing_secret' => $secret, // optional — one is generated when omitted
]);
$hook['signing_secret'];
$ms->webhooks->list();
$ms->webhooks->get($id); // the only read that urs' => 0]); // bring your own; 0..72
$rotated['signing_secret'];
$rotated['previous_secret_expires_at']; // ISO timestamp while the old secret still co-signs deliveries, else null
$key = $ms->apiKeys->create([
'name' => 'ci',
'permission' => 'sending_access', // full_access (default) | sending_access
'domain_id' => $domainId, // optional: restrict a sending key to one domain
]);
$key['token']; // shown once, never returned again
$ms->apiKeys->list();
$ms->apiKeys->remove($id);