MailerEngagementEvent example

<?php
use Symfony\Component\RemoteEvent\Event\Mailer\MailerEngagementEvent;

$wh = new MailerEngagementEvent(MailerEngagementEvent::OPEN, '<201798300811.5787683@relay.domain.com>', json_decode(file_get_contents(str_replace('.php', '.json', __FILE__)), true, flags: JSON_THROW_ON_ERROR));
$wh->setRecipientEmail('example@gmail.com');
$wh->setTags(['transactionalTag']);
$wh->setDate(\DateTimeImmutable::createFromFormat('U', 1604933654));

return $wh;
<?php
use Symfony\Component\RemoteEvent\Event\Mailer\MailerEngagementEvent;

$wh = new MailerEngagementEvent(MailerEngagementEvent::CLICK, '93449692684977140', json_decode(file_get_contents(str_replace('.php', '.json', __FILE__)), true, flags: JSON_THROW_ON_ERROR));
$wh->setRecipientEmail('event-click@hotmail.com');
$wh->setDate(\DateTimeImmutable::createFromFormat('U', 1685519224));
$wh->setTags(['helloworld']);
$wh->setMetadata(['Payload' => '']);

return $wh;
<?php
use Symfony\Component\RemoteEvent\Event\Mailer\MailerEngagementEvent;

$wh = new MailerEngagementEvent(MailerEngagementEvent::CLICK, '00000000-0000-0000-0000-000000000000', json_decode(file_get_contents(str_replace('.php', '.json', __FILE__)), true));
$wh->setRecipientEmail('john@example.com');
$wh->setTags(['welcome-email']);
$wh->setMetadata(['example' => 'value', 'example_2' => 'value']);
$wh->setDate(\DateTimeImmutable::createFromFormat('Y-m-d\TH:i:sT', '2022-09-02T14:31:09Z'));

return $wh;
<?php
use Symfony\Component\RemoteEvent\Event\Mailer\MailerEngagementEvent;

$wh = new MailerEngagementEvent(MailerEngagementEvent::OPEN, '00000000-0000-0000-0000-000000000000', json_decode(file_get_contents(str_replace('.php', '.json', __FILE__)), true));
$wh->setRecipientEmail('john@example.com');
$wh->setTags(['welcome-email']);
$wh->setMetadata(['example' => 'value', 'example_2' => 'value']);
$wh->setDate(\DateTimeImmutable::createFromFormat('Y-m-d\TH:i:sT', '2022-09-02T14:30:47Z'));

return $wh;
<?php
use Symfony\Component\RemoteEvent\Event\Mailer\MailerEngagementEvent;

$wh = new MailerEngagementEvent(MailerEngagementEvent::UNSUBSCRIBE, '<202305311328.81899448177@smtp-relay.mailin.fr>', json_decode(file_get_contents(str_replace('.php', '.json', __FILE__)), true, flags: JSON_THROW_ON_ERROR));
$wh->setRecipientEmail('example@gmail.com');
$wh->setTags(['tag1', 'tag2']);
$wh->setDate(\DateTimeImmutable::createFromFormat('U', 1685541121));

return $wh;
$event = new MailerDeliveryEvent($name$payload['id']$payload);
            // reason is only available on failed messages             $event->setReason($this->getReason($payload));
        } else {
            $name = match ($payload['event']) {
                'clicked' => MailerEngagementEvent::CLICK,
                'unsubscribed' => MailerEngagementEvent::UNSUBSCRIBE,
                'opened' => MailerEngagementEvent::OPEN,
                'complained' => MailerEngagementEvent::SPAM,
                default => throw new ParseException(sprintf('Unsupported event "%s".', $payload['event'])),
            };
            $event = new MailerEngagementEvent($name$payload['id']$payload);
        }
        if (!$date = \DateTimeImmutable::createFromFormat('U.u', $payload['timestamp'])) {
            throw new ParseException(sprintf('Invalid date "%s".', $payload['timestamp']));
        }
        $event->setDate($date);
        $event->setRecipientEmail($payload['recipient']);
        $event->setMetadata($payload['user-variables']);
        $event->setTags($payload['tags']);

        return $event;
    }

    
<?php
use Symfony\Component\RemoteEvent\Event\Mailer\MailerEngagementEvent;

$wh = new MailerEngagementEvent(MailerEngagementEvent::CLICK, 'Ase7i2zsRYeDXztHGENqRA', json_decode(file_get_contents(str_replace('.php', '.json', __FILE__)), true, flags: JSON_THROW_ON_ERROR)['event-data']);
$wh->setRecipientEmail('alice@example.com');
$wh->setTags(['my_tag_1', 'my_tag_2']);
$wh->setMetadata(['my_var_1' => 'Mailgun Variable #1', 'my-var-2' => 'awesome']);
$wh->setDate(\DateTimeImmutable::createFromFormat('U.u', 1521243339.873676));

return $wh;
<?php
use Symfony\Component\RemoteEvent\Event\Mailer\MailerEngagementEvent;

$wh = new MailerEngagementEvent(MailerEngagementEvent::OPEN, '<202305311447.66548003588@smtp-relay.mailin.fr>', json_decode(file_get_contents(str_replace('.php', '.json', __FILE__)), true, flags: JSON_THROW_ON_ERROR));
$wh->setRecipientEmail('example@gmail.com');
$wh->setTags(['welcome', 'tag2']);
$wh->setDate(\DateTimeImmutable::createFromFormat('U', 1685544532));

return $wh;
<?php
use Symfony\Component\RemoteEvent\Event\Mailer\MailerEngagementEvent;

$wh = new MailerEngagementEvent(MailerEngagementEvent::OPEN, 'Ase7i2zsRYeDXztHGENqRA', json_decode(file_get_contents(str_replace('.php', '.json', __FILE__)), true, flags: JSON_THROW_ON_ERROR)['event-data']);
$wh->setRecipientEmail('alice@example.com');
$wh->setTags(['my_tag_1', 'my_tag_2']);
$wh->setMetadata(['my_var_1' => 'Mailgun Variable #1', 'my-var-2' => 'awesome']);
$wh->setDate(\DateTimeImmutable::createFromFormat('U.u', 1521243339.873676));

return $wh;

            $event = new MailerDeliveryEvent($name$payload['MessageID']$payload);
            $event->setReason($payload['Description'] ?? '');
        } else {
            $name = match ($payload['RecordType']) {
                'Click' => MailerEngagementEvent::CLICK,
                'SubscriptionChange' => MailerEngagementEvent::UNSUBSCRIBE,
                'Open' => MailerEngagementEvent::OPEN,
                'SpamComplaint' => MailerEngagementEvent::SPAM,
                default => throw new ParseException(sprintf('Unsupported event "%s".', $payload['RecordType'])),
            };
            $event = new MailerEngagementEvent($name$payload['MessageID']$payload);
        }
        $payloadDate = match ($payload['RecordType']) {
            'Delivery' => $payload['DeliveredAt'],
            'Bounce' => $payload['BouncedAt'],
            'Click' => $payload['ReceivedAt'],
            'SubscriptionChange' => $payload['ChangedAt'],
            'Open' => $payload['ReceivedAt'],
            'SpamComplaint' => $payload['BouncedAt'],
            default => throw new ParseException(sprintf('Unsupported event "%s".', $payload['RecordType'])),
        };
        if (!$date = \DateTimeImmutable::createFromFormat('Y-m-d\TH:i:sT', $payloadDate)) {
            
<?php
use Symfony\Component\RemoteEvent\Event\Mailer\MailerEngagementEvent;

$wh = new MailerEngagementEvent(MailerEngagementEvent::UNSUBSCRIBE, 'Ase7i2zsRYeDXztHGENqRA', json_decode(file_get_contents(str_replace('.php', '.json', __FILE__)), true, flags: JSON_THROW_ON_ERROR)['event-data']);
$wh->setRecipientEmail('alice@example.com');
$wh->setTags(['my_tag_1', 'my_tag_2']);
$wh->setMetadata(['my_var_1' => 'Mailgun Variable #1', 'my-var-2' => 'awesome']);
$wh->setDate(\DateTimeImmutable::createFromFormat('U.u', 1521243339.873676));

return $wh;
<?php
use Symfony\Component\RemoteEvent\Event\Mailer\MailerEngagementEvent;

$wh = new MailerEngagementEvent(MailerEngagementEvent::OPEN, '102175416994919440', json_decode(file_get_contents(str_replace('.php', '.json', __FILE__)), true, flags: JSON_THROW_ON_ERROR));
$wh->setRecipientEmail('event-open@gmail.com');
$wh->setDate(\DateTimeImmutable::createFromFormat('U', 1685519055));
$wh->setTags(['helloworld']);
$wh->setMetadata(['Payload' => '']);

return $wh;
$event = new MailerDeliveryEvent($name$payload['MessageID']$payload);
            $event->setReason($this->getReason($payload));
        } else {
            $name = match ($payload['event']) {
                'click' => MailerEngagementEvent::CLICK,
                'open' => MailerEngagementEvent::OPEN,
                'spam' => MailerEngagementEvent::SPAM,
                'unsub' => MailerEngagementEvent::UNSUBSCRIBE,
                default => throw new ParseException(sprintf('Unsupported event "%s".', $payload['event'])),
            };
            $event = new MailerEngagementEvent($name$payload['MessageID']$payload);
        }

        if (!$date = \DateTimeImmutable::createFromFormat('U', $payload['time'])) {
            throw new ParseException(sprintf('Invalid date "%s".', $payload['time']));
        }

        $event->setDate($date);
        $event->setRecipientEmail($payload['email']);

        if (isset($payload['CustomID'])) {
            $event->setTags([$payload['CustomID']]);
        }
<?php
use Symfony\Component\RemoteEvent\Event\Mailer\MailerEngagementEvent;

$wh = new MailerEngagementEvent(MailerEngagementEvent::CLICK, '<202305311408.17112967225@smtp-relay.mailin.fr>', json_decode(file_get_contents(str_replace('.php', '.json', __FILE__)), true, flags: JSON_THROW_ON_ERROR));
$wh->setRecipientEmail('example@gmail.com');
$wh->setTags(['welcome', 'tag2']);
$wh->setDate(\DateTimeImmutable::createFromFormat('U', 1685542108));

return $wh;

            $event = new MailerDeliveryEvent($name$payload['sg_message_id']$payload);
            $event->setReason($payload['reason'] ?? '');
        } else {
            $name = match ($payload['event']) {
                'click' => MailerEngagementEvent::CLICK,
                'unsubscribe' => MailerEngagementEvent::UNSUBSCRIBE,
                'open' => MailerEngagementEvent::OPEN,
                'spamreport' => MailerEngagementEvent::SPAM,
                default => throw new ParseException(sprintf('Unsupported event "%s".', $payload['unsubscribe'])),
            };
            $event = new MailerEngagementEvent($name$payload['sg_message_id']$payload);
        }

        if (!$date = \DateTimeImmutable::createFromFormat('U', $payload['timestamp'])) {
            throw new ParseException(sprintf('Invalid date "%s".', $payload['timestamp']));
        }

        $event->setDate($date);
        $event->setRecipientEmail($payload['email']);
        $event->setMetadata([]);
        $event->setTags($payload['category'] ?? []);

        
Home | Imprint | This part of the site doesn't use cookies.