PHP code example of senderkit / senderkit-php

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

    

senderkit / senderkit-php example snippets


use SenderKit\Client;
use SenderKit\Request\TemplateSend;

$sk = new Client(apiKey: getenv('SENDERKIT_API_KEY')); // sk_live_… or sk_test_…

$result = $sk->send(new TemplateSend(
    template: 'welcome',
    to: '[email protected]',
    vars: ['name' => 'Ada'],
));

echo $result->id;     // msg_…
echo $result->status; // queued | scheduled

use SenderKit\Request\{RawSend, EmailContent};

$sk->sendRaw(new RawSend(
    to: '[email protected]',
    content: new EmailContent(subject: 'Receipt', html: '<p>Thanks for your order.</p>'),
    metadata: ['source' => 'checkout'],
));

use SenderKit\Webhook\WebhookVerifier;

$event = (new WebhookVerifier)->verify(
    rawBody: $rawRequestBody,
    signatureHeader: $request->header('X-SenderKit-Signature'),
    secret: getenv('SENDERKIT_WEBHOOK_SECRET'), // whsec_…
);

echo $event->type; // message.delivered, message.failed, …
bash
composer