PHP code example of sendery / php

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

    

sendery / php example snippets




use Sendery\Client;

$sendery = new Client(getenv('SENDERY_API_KEY'));
$receipt = $sendery->send(
    to: '[email protected]',
    template: 'your-template',
    data: ['name' => 'Alex', 'action_url' => 'https://example.com/start'],
);

echo $receipt['id'];

$receipt = $sendery->prepare(
    to: '[email protected]',
    template: 'your-template',
    data: ['name' => 'Alex', 'action_url' => 'https://example.com/start'],
)->version(3)->send();

use Sendery\Attachment;

$sendery->prepare(
    to: '[email protected]',
    template: 'your-template',
    data: ['name' => 'Alex', 'action_url' => 'https://example.com/start'],
    idempotencyKey: 'your-idempotency-key',
    attachments: [
        Attachment::fromPath('/path/document.pdf', 'document.pdf', 'application/pdf'),
    ],
)->retry()->send();

$message = $sendery->get($receipt['id']);
echo $message['status'];

$email = $sendery->prepare(
    to: '[email protected]',
    template: 'your-template',
    data: ['name' => 'Alex', 'action_url' => 'https://example.com/start'],
    idempotencyKey: 'your-idempotency-key',
);
$receipt = $email->retry(3)->send();

try {
    $receipt = $email->retry(3)->send();
} catch (\Sendery\ApiException $error) {
    error_log($error->status.': '.$error->errorCode);
    // $error->errors contains field-level validation errors.
    // $error->retryAfter is a delay in seconds, when provided.
    throw $error;
}
bash
composer