Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.mailbreeze.com/llms.txt

Use this file to discover all available pages before exploring further.

Installation

composer require mailbreeze/mailbreeze-php

Requirements

  • PHP 8.1+
  • Guzzle HTTP client (auto-installed)

Quick Start

<?php

require_once 'vendor/autoload.php';

use MailBreeze\MailBreeze;

$mailbreeze = new MailBreeze(getenv('MAILBREEZE_API_KEY'));

$result = $mailbreeze->emails->send([
    'from' => 'hello@yourdomain.com',
    'to' => ['user@example.com'],
    'subject' => 'Welcome!',
    'html' => '<h1>Welcome to our platform!</h1>',
]);

echo "Email sent: " . $result['data']['id'];

Configuration

$mailbreeze = new MailBreeze(
    getenv('MAILBREEZE_API_KEY'),
    [
        'base_url' => 'https://api.mailbreeze.com',  // Optional
        'timeout' => 30,                              // Optional (seconds)
        'max_retries' => 3,                           // Optional
    ]
);

Resources

Emails

// Send email
$result = $mailbreeze->emails->send([
    'from' => 'hello@yourdomain.com',
    'to' => ['user@example.com'],
    'subject' => 'Hello',
    'html' => '<p>Hello!</p>',
]);
echo "Sent: " . $result['data']['id'];

// Send with template
$result = $mailbreeze->emails->send([
    'from' => 'hello@yourdomain.com',
    'to' => ['user@example.com'],
    'template_id' => 'welcome-template',
    'variables' => ['name' => 'John'],
]);

// List emails
$result = $mailbreeze->emails->list([
    'status' => 'delivered',
    'page' => 1,
    'limit' => 20,
]);
foreach ($result['data'] as $email) {
    echo $email['subject'] . "\n";
}

// Get email
$email = $mailbreeze->emails->get('msg_xxx');

// Get stats
$stats = $mailbreeze->emails->stats();
echo "Total: " . $stats['data']['total'];

Attachments

// Create presigned upload URL
$upload = $mailbreeze->attachments->createUploadUrl([
    'filename' => 'report.pdf',
    'contentType' => 'application/pdf',
    'size' => 1024000,
]);

// Upload file (use Guzzle or any HTTP client)
$client = new \GuzzleHttp\Client();
$client->put($upload['data']['uploadUrl'], [
    'body' => file_get_contents('report.pdf'),
    'headers' => ['Content-Type' => 'application/pdf'],
]);

// Use the attachment ID when sending emails
$mailbreeze->emails->send([
    'from' => 'hello@yourdomain.com',
    'to' => ['user@example.com'],
    'subject' => 'Your Report',
    'html' => '<p>Please find your report attached.</p>',
    'attachment_ids' => [$upload['data']['attachmentId']],
]);

Lists

// Create list
$list = $mailbreeze->lists->create([
    'name' => 'Newsletter',
    'description' => 'Weekly newsletter subscribers',
]);
echo "Created: " . $list['data']['id'];

// List all
$result = $mailbreeze->lists->list();
foreach ($result['data'] as $list) {
    echo $list['name'] . "\n";
}

// Get, update, delete
$list = $mailbreeze->lists->get('lst_xxx');
$list = $mailbreeze->lists->update('lst_xxx', [
    'name' => 'New Name',
]);
$mailbreeze->lists->delete('lst_xxx');

// Get stats
$stats = $mailbreeze->lists->stats('lst_xxx');

// Add/remove contacts from list
$mailbreeze->lists->addContact('lst_xxx', 'cnt_xxx');
$mailbreeze->lists->removeContact('lst_xxx', 'cnt_xxx');

// Get list contacts
$contacts = $mailbreeze->lists->contacts('lst_xxx');

Contacts

// Create contact
$contact = $mailbreeze->contacts->create([
    'email' => 'user@example.com',
    'first_name' => 'John',
    'last_name' => 'Doe',
    'custom_fields' => ['company' => 'Acme'],
]);
echo "Created: " . $contact['data']['id'];

// List contacts
$result = $mailbreeze->contacts->list(['status' => 'active']);
foreach ($result['data'] as $contact) {
    echo $contact['email'] . "\n";
}

// Get, update, delete
$contact = $mailbreeze->contacts->get('cnt_xxx');
$contact = $mailbreeze->contacts->update('cnt_xxx', [
    'first_name' => 'Jane',
]);
$mailbreeze->contacts->delete('cnt_xxx');

// Unsubscribe/resubscribe contact
$mailbreeze->contacts->unsubscribe('cnt_xxx');
$mailbreeze->contacts->resubscribe('cnt_xxx');

Verification

// Verify single email
$result = $mailbreeze->verification->verify(['email' => 'user@example.com']);
if ($result['data']['is_valid']) {
    echo "Safe to send";
} else {
    echo "Invalid: " . $result['data']['status'];
}

// Batch verify
$batch = $mailbreeze->verification->batch([
    'user1@example.com',
    'user2@example.com',
]);

// Poll for results
$status = $mailbreeze->verification->get($batch['data']['verification_id']);

// List verifications and get stats
$result = $mailbreeze->verification->list();
$stats = $mailbreeze->verification->stats();

Error Handling

use MailBreeze\MailBreeze;
use MailBreeze\Exceptions\MailBreezeException;
use MailBreeze\Exceptions\ValidationException;
use MailBreeze\Exceptions\AuthenticationException;
use MailBreeze\Exceptions\RateLimitException;

try {
    $mailbreeze->emails->send([...]);
} catch (ValidationException $e) {
    // Invalid request data (422)
    echo $e->getMessage();     // Human-readable message
    print_r($e->getErrors());  // Field-specific errors
} catch (AuthenticationException $e) {
    // Invalid API key (401)
    echo $e->getMessage();
} catch (RateLimitException $e) {
    // Too many requests (429)
    echo "Retry after: " . $e->getRetryAfter() . " seconds";
} catch (MailBreezeException $e) {
    // Other API errors
    echo $e->getMessage();
}

Exception Types

ExceptionHTTP StatusDescription
ValidationException400Invalid request parameters
AuthenticationException401Invalid or missing API key
ForbiddenException403Access denied to resource
NotFoundException404Resource not found
RateLimitException429Rate limit exceeded
ServerException5xxServer-side error
MailBreezeException*Base exception class

Laravel Integration

// config/services.php
return [
    'mailbreeze' => [
        'api_key' => env('MAILBREEZE_API_KEY'),
    ],
];

// app/Providers/AppServiceProvider.php
use MailBreeze\MailBreeze;

public function register(): void
{
    $this->app->singleton(MailBreeze::class, function () {
        return new MailBreeze(config('services.mailbreeze.api_key'));
    });
}

// Usage in controller
public function sendWelcome(Request $request, MailBreeze $mailbreeze)
{
    $mailbreeze->emails->send([
        'from' => 'welcome@yourdomain.com',
        'to' => [$request->user()->email],
        'template_id' => 'welcome',
        'variables' => ['name' => $request->user()->name],
    ]);
}

Features

  • PSR-4 autoloading - Standard PHP autoloading
  • Guzzle HTTP - Battle-tested HTTP client
  • Typed exceptions - Specific exception classes for each error type
  • Automatic retries - Exponential backoff for transient failures
  • PHPStan level 8 - Full static analysis
  • 95%+ test coverage

Packagist

View on Packagist

GitHub

Source code