Download the PHP package couryo/couryo-php without Composer
On this page you can find all versions of the php package couryo/couryo-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download couryo/couryo-php
More information about couryo/couryo-php
Files in couryo/couryo-php
Package couryo-php
Short Description Official PHP SDK for the Couryo email API: retries, automatic Idempotency-Key, webhook verification and a Laravel mail transport.
License MIT
Homepage https://couryo.com
Informations about the package couryo-php
couryo/couryo-php
Official PHP SDK for the Couryo email API. Leia em português.
- Automatic
Idempotency-Keyon every POST, reused on retries: a send that timed out but went through is never duplicated. - Retries with backoff for network errors,
5xxandrate_limited(honorsRetry-After). Errors that would fail again (domain_not_verified,daily_limit_reached...) are thrown right away. - Typed exceptions with the API error
code. - Webhook verification (Standard Webhooks) in one call.
- Laravel mail transport (
MAIL_MAILER=couryo), also usable with Symfony Mailer. - PHP 8.1 or newer with
ext-curlandext-json. No runtime dependencies; any PSR-18 client can replace curl.
Not on Packagist yet. Inside the Couryo monorepo it lives in
packages/sdk-php; until it is published, install it from a path repository (see below).
Install
Before it is on Packagist, point Composer to the folder:
Send an email
Responses are associative arrays with the same fields as the API JSON.
Pass your own key when the same business event may be sent twice: $couryo->emails->send($body, ['idempotency_key' => 'order-1042-confirmation']). Every POST method accepts this options array.
Saved templates
Contacts, events and campaigns
Errors
PHP reserves Exception::$code for an integer, so the API code (domain_not_verified, rate_limited...) is in getErrorCode() and in the $e->errorCode property, and getCode() returns the HTTP status (0 for network errors). Also available: getType(), getDocUrl(), getRetryAfter() and getError() (the whole error object).
Each type has its own class, all extending CouryoException: InvalidRequestError, AuthenticationError, PermissionError, NotFoundError, ConflictError, RateLimitError, TierLimitError, ApiError and NetworkError (network failure or timeout, status 0).
message follows the language option (pt-BR by default, or en).
Webhooks
Use the raw body exactly as it arrived, never JSON that was decoded and encoded again.
Plain PHP:
Laravel (a route without CSRF protection, such as routes/api.php):
Webhook::verify accepts any header array (getallheaders(), $_SERVER, $request->headers->all()), looks them up without case sensitivity and throws WebhookVerificationError for a wrong signature or a timestamp older than 5 minutes ($toleranceSeconds, the fourth argument). Webhook::sign() builds a valid signature for your tests.
Laravel
The service provider is discovered automatically. It reads COURYO_API_KEY (or config('services.couryo.key')), binds Couryo\Couryo as a singleton (also app('couryo')) and registers the couryo mail transport.
.env:
config/mail.php, inside mailers:
Then send as usual:
From, to, cc, bcc, reply-to, subject, HTML, text, attachments and inline images go to the API. Tags (tags: [...] in the Mailable envelope or ->tag()) become Couryo tags (as does an X-Couryo-Tags: kind=order, store=downtown header), metadata becomes metadata, other X-* headers go in headers, and an X-Couryo-Stream: marketing header picks the stream. php artisan vendor:publish --tag=couryo-config copies config/couryo.php to your app.
The transport is a regular Symfony Mailer transport, so it also works outside Laravel: new Symfony\Component\Mailer\Mailer(new Couryo\Laravel\CouryoTransport($couryo)).
Or plain SMTP
No package needed, with Laravel's smtp mailer:
Ports 587 and 2525 use STARTTLS, 465 uses TLS. The password is an API key with the send or admin scope.
PSR-18 client instead of curl
Needs psr/http-client and psr/http-factory. PSR-18 has no per-request timeout, so set it on your client. You can also write your own Couryo\Http\Transport (one send() method).
Everything else
| Resource | Methods |
|---|---|
emails |
send, batch (up to 100), check, get, list, iterate |
domains |
list, create, get, delete, verify, health (deliverability diagnosis) |
webhooks |
list, create, get, update, delete |
suppressions |
list, add, remove |
events |
list, iterate (delivery events), track (contact event) |
templates |
list, create, get, update, delete, versions, preview |
contacts |
create (upsert), list, get, update, delete, iterate, count |
campaigns |
create, list, get, update, delete, preflight, send, schedule, pause, resume, cancel, test, stats |
iterate walks every page: foreach ($couryo->emails->iterate(['status' => 'bounced']) as $email) { ... }.
Options: api_key, base_url, max_retries (2), timeout (30 s per attempt), language, transport, sleep.
All versions of couryo-php with dependencies
ext-curl Version *
ext-json Version *