PHP SDK
Overview
The Brevo PHP SDK (getbrevo/brevo-php) is a type-safe client library for the Brevo API. It provides:
- A unified
Brevoclient with namespaced service clients - Strongly typed request and response objects with full PHPDoc annotations
- PSR-18 HTTP client compatibility (Guzzle, Symfony HttpClient, etc.)
- Automatic retries with exponential backoff
- Structured error handling via
BrevoApiException
Version 4.0 is a full rewrite and is not backwards compatible with the legacy SDK. The legacy SDK will continue to receive critical security updates but no new features. We recommend migrating to v4.x for new and existing projects.
Requirements
- PHP 8.1+
ext-json- A PSR-18 HTTP client (e.g., Guzzle, Symfony HttpClient)
Installation
Install the SDK using Composer:
Guzzle is recommended as the HTTP client:
If no HTTP client is provided, the SDK uses php-http/discovery to auto-detect an installed PSR-18 client.
Quick start
Initialize the client and send your first email:
Configuration
Pass an options array as the second argument to configure the client:
Constructor parameters
Error handling
BrevoApiException is thrown for any non-2xx HTTP response. Catch it to inspect the status code and response body:
Exception classes
BrevoApiException exposes:
getCode()— HTTP status codegetMessage()— Error messagegetBody()— Parsed response body
Status codes
Retries
Automatic retries with exponential backoff are enabled by default (2 retries). Configure at the client or request level:
Retry behavior
- Retryable status codes:
408,429,5xx - Backoff schedule: ~1s, ~2s, ~4s (exponential, base 1000ms) with ±10% symmetric jitter
- Maximum delay: 60s per retry interval
- Rate limit headers: Respects
Retry-AfterandX-RateLimit-Resetresponse headers
Timeouts
No default timeout is configured. Unless you set one, the underlying HTTP client’s default applies (Guzzle defaults to no timeout). Set an explicit timeout at the client or request level:
Timeout forwarding is supported for Guzzle and Symfony HttpClient. For other PSR-18 clients, the timeout value is ignored and a PHP warning is triggered.
Recommended timeout values
Request options
Both timeout, maxRetries, and headers can be overridden per request by passing an options array as the last argument:
Query parameters
Pass query parameters via the typed request object:
Binary responses
Some endpoints (e.g., attachment downloads) return binary content directly:
Type safety
All request and response objects are strongly typed. Use the generated request classes for IDE autocomplete and static analysis:
Custom HTTP client
Pass any PSR-18-compatible client via the client option:
Common integrations
Guzzle
Symfony HttpClient
Laravel
Register the client as a singleton in a service provider:
PHP-specific considerations
API key from environment
Avoid hardcoding API keys. Use environment variables:
In Laravel, use config('services.brevo.api_key'). In Symfony, use $_ENV['BREVO_API_KEY'] or service parameters.
Memory limits
For large operations (bulk exports, large attachments), adjust PHP’s memory_limit:
Available services
The unified Brevo client exposes the following service namespaces: