1. Go to this page and download the library: Download easymailing/sdk-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/ */
use Easymailing\Sdk\Hydra\IriExtractor;
IriExtractor::extract('/audiences/AUD-UUID/members/MEM-UUID'); // "MEM-UUID"
use Easymailing\Sdk\Transport\WordPressTransport;
$em = new Easymailing(
apiKey: '...',
transport: new WordPressTransport(timeoutSeconds: 30),
);
use Easymailing\Sdk\Easymailing;
use Easymailing\Sdk\Telemetry\SdkEvent;
use Easymailing\Sdk\Telemetry\EventTypes;
$em = new Easymailing(
apiKey: '...',
onEvent: function (SdkEvent $event): void {
match ($event->type) {
EventTypes::REQUEST_END => $myLogger->log([
'requestId' => $event->requestId,
'pathTemplate' => $event->pathTemplate, // "/audiences/{audienceUuid}/members/{uuid}" — metric-safe
'status' => $event->payload['status'],
'durationMs' => $event->payload['durationMs'],
'error' => $event->payload['error'] ?? null, // 422 violations preserved
]),
EventTypes::WEBHOOK_REJECTED => $siem->alert($event->payload),
default => null,
};
},
);
use Easymailing\Sdk\Easymailing;
use Easymailing\Sdk\Telemetry\Psr3EventListener;
$em = new Easymailing(
apiKey: '...',
onEvent: new Psr3EventListener($monolog),
);
use Easymailing\Sdk\Batch\BatchTypes\BatchOperation;
$result = $em->batch->run([
new BatchOperation(
method: 'POST',
path: '/audiences/AUD-UUID/members',
body: ['email' => '[email protected]'], // SDK serializes arrays automatically
externalIdentifier: 'import-1',
),
]);
echo $result->snapshot->status; // "finished"
echo count($result->responses ?? []); // number of operations
echo $result->errors?->totalErrors ?? 0; // null if no errors
// In your controller — returns in one round-trip:
$snapshots = $em->batch->runAsync($operations);
$this->db->saveJob(['batch_uuid' => $snapshots[0]->uuid, 'status' => 'pending']);
return new JsonResponse(['job_id' => $snapshots[0]->uuid], 202);
// Later, in a Symfony Messenger consumer or worker process:
$em->batch->wait($uuid);
$responses = $em->batch->fetchResponsesGuaranteed($uuid);
$em = new Easymailing(apiKey: '...');
if ($em->webhooks->verify($rawBody, $signature, $secret)) {
$event = $em->webhooks->parse($rawBody);
error_log($event['event_type']);
}
use Easymailing\Sdk\Generated\Webhooks\WebhookEvents;
$event = $em->webhooks->parse($rawBody);
match ($event['event_type']) {
WebhookEvents::MEMBER_SUBSCRIBED => handleSubscribed($event['data']),
WebhookEvents::MEMBER_CAMPAIGN_BOUNCED => handleBounce($event['data']),
default => null, // unknown event types still arrive
};
bash
composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.