PHP SDK

Use your favorite mail provider Zupost, seamless with our PHP SDK.

Static Analysis

PHPStan integration for code quality

PSR Compliant

Follows modern PHP standards

There are many various ways of sending emails with Zupost. It can be a template, created in our no-code-editor. HTML or just markdown. No matter what you prefer, Zupost has it for you. And if you encounter issues with the documentation or the SDK, don't hesitate to open a Issue.

Installation

Start by installing the official Zupost package with composer.
composer require zupost/zupost

Setting Up

After successfully installing Zupost to your project, you can start by creating a Zupost instance.

<?php

require_once 'vendor/autoload.php';

use Zupost\Zupost;

$zupost = new Zupost('your-api-key');

Sending Emails

You can send emails in various ways, see some usage examples:

// Send with HTML content
$response = $zupost->emails->send([
    'from' => 'sender@example.com',
    'to' => 'recipient@example.com',
    'subject' => 'Hello World',
    'html' => '<h1>Hello!</h1>',
]);
echo $response->id;

// Send to multiple recipients
$zupost->emails->send([
    'from' => 'sender@example.com',
    'to' => ['user1@example.com', 'user2@example.com'],
    'subject' => 'Team Update',
    'markdown' => "# Hello Team\n\nThis is a **markdown** email.",
]);

// Send with a template
$zupost->emails->send([
    'from' => 'sender@example.com',
    'to' => 'recipient@example.com',
    'subject' => 'Welcome!',
    'templateId' => 'welcome-template',
    'variables' => ['name' => 'John'],
]);

With Attachments

You can attach files to your emails by providing them as base64-encoded strings.

$zupost->emails->send([
    'from' => 'sender@example.com',
    'to' => 'recipient@example.com',
    'subject' => 'Invoice',
    'html' => '<p>Please find the invoice attached.</p>',
    'attachments' => [
        [
            'filename' => 'invoice.pdf',
            'content' => base64_encode(file_get_contents('/path/to/invoice.pdf')),
        ],
    ],
]);

Error Handling

use Zupost\Exception\ApiException;
use Zupost\Exception\ValidationException;
use Zupost\Exception\ZupostException;

try {
    $response = $zupost->emails->send([
        'from' => 'sender@example.com',
        'to' => 'recipient@example.com',
        'subject' => 'Hello',
        'html' => '<h1>Hello!</h1>',
    ]);
} catch (ValidationException $e) {
    // Handle validation errors
    echo 'Validation error: ' . $e->getMessage();
} catch (ApiException $e) {
    // Handle API errors
    echo 'API error: ' . $e->getMessage();
    echo 'Status code: ' . $e->getCode();
    print_r($e->getResponseBody());
} catch (ZupostException $e) {
    // Handle general errors
    echo 'Error: ' . $e->getMessage();
}

Contribute on GitHub

Found an issue or want to contribute? Check out the repository for this project. We welcome contributions of all kinds!

PHP SDK