PHPackages                             absmugz/courier - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. absmugz/courier

ActiveLibrary[API Development](/categories/api)

absmugz/courier
===============

Courier PHP Library

v2.0.3(1y ago)01.4k↓16.7%PHPPHP ^8.1

Since Mar 31Pushed 1y agoCompare

[ Source](https://github.com/absmugz/courier-php)[ Packagist](https://packagist.org/packages/absmugz/courier)[ RSS](/packages/absmugz-courier/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (4)Versions (2)Used By (0)

Courier PHP SDK
===============

[](#courier-php-sdk)

[![fern shield](https://camo.githubusercontent.com/7cfaf5314e1b5d061cd50428e99e60c0cab6c3fa9b20995623b13f52f7a68778/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f2546302539462538432542462d53444b25323067656e65726174656425323062792532304665726e2d627269676874677265656e)](https://github.com/fern-api/fern)[![php shield](https://camo.githubusercontent.com/c6935ea725f448fdb79c5a9a86bf2f898610c8bf44028a3192176889b47cdba6/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d7061636b61676973742d70696e6b)](https://packagist.org/packages/trycourier/courier)

The Courier PHP library provides convenient access to the Courier API from PHP.

Requirements
------------

[](#requirements)

Use of the Courier PHP SDK requires:

- PHP ^8.1

Installation
------------

[](#installation)

Use Composer to configure and install the Courier PHP SDK:

```
composer require trycourier/courier
```

Usage
-----

[](#usage)

```
use Courier\CourierClient;
use Courier\Requests\SendMessageRequest;
use Courier\Send\Types\ContentMessage;
use Courier\Send\Types\ElementalContentSugar;
use Courier\Send\Types\UserRecipient;

$courier = new CourierClient();
$response = $courier->send(
    request: new SendMessageRequest([
        'message' => new ContentMessage([
            'to' => [
                new UserRecipient([
                    'email' => 'marty_mcfly@email.com',
                    'data' => [
                        'name' => 'Marty',
                    ],
                ]),
            ],
            'content' => new ElementalContentSugar([
                'title' => 'Back to the Future',
                'body' => 'Oh my {{name}}, we need 1.21 Gigawatts!',
            ]),
        ]),
    ])
);
```

Instantiation
-------------

[](#instantiation)

To get started with the Courier SDK, instantiate the `CourierClient` class as follows:

```
use Courier\CourierClient;

$courier = new CourierClient("COURIER_AUTH_TOKEN");
```

Alternatively, you can omit the token when constructing the client. In this case, the SDK will automatically read the token from the `COURIER_AUTH_TOKEN` environment variable:

```
use Courier\CourierClient;

$courier = new CourierClient(); // Token is read from the COURIER_AUTH_TOKEN environment variable
```

### Environment and Custom URLs

[](#environment-and-custom-urls)

This SDK allows you to configure different environments or custom URLs for API requests. You can either use the predefined environments or specify your own custom URL.

#### Environments

[](#environments)

```
use Courier\CourierClient;
use Courier\Environments;

$courier = new CourierClient(options: [
    'baseUrl' => Environments::Production->value // Used by default
]);
```

#### Custom URL

[](#custom-url)

```
use Courier\CourierClient;

$courier = new CourierClient(options: [
    'baseUrl' => 'https://custom-staging.com'
]);
```

Enums
-----

[](#enums)

This SDK leverages PHP 8.1's first-class enums to improve type safety and usability. In order to maintain forward compatibility with the API—where new enum values may be introduced in the future—we define enum properties as `string`and use `value-of` annotations to specify the corresponding enum type.

### Example Usage

[](#example-usage)

```
use Courier\Messages\Types\MessageDetails;
use Courier\Messages\Types\MessageStatus;

$messageDetails = new MessageDetails([
    'status' => MessageStatus::Delivered->value,
]);
```

### PHPDoc Annotations

[](#phpdoc-annotations)

```
/**
 * @var value-of $status The current status of the message.
 */
```

Exception Handling
------------------

[](#exception-handling)

When the API returns a non-zero status code, (`4xx` or `5xx` response), a `CourierApiException` will be thrown:

```
use Courier\Exceptions\CourierApiException;
use Courier\Exceptions\CourierException;

try {
    $courier->lists->get(...);
} catch (CourierApiException $e) {
    echo 'Courier API Exception occurred: ' . $e->getMessage() . "\n";
    echo 'Status Code: ' . $e->getCode() . "\n";
    echo 'Response Body: ' . $e->getBody() . "\n";
    // Optionally, rethrow the exception or handle accordingly
}
```

Advanced
--------

[](#advanced)

### Pagination

[](#pagination)

The SDK supports pagination for endpoints that return lists of items:

```
use Courier\Lists\Requests\GetAllListsRequest;

$items = $courier->lists->list(
    request: new GetAllListsRequest([
        'cursor' => 'abc123',
        'pageSize' => 10,
    ])
)->items;

foreach ($items as $list) {
    echo "Found list with ID: " . $list->id . "\n";
}
```

### Custom HTTP Client

[](#custom-http-client)

This SDK is built to work with any HTTP client that implements Guzzle's `ClientInterface`. By default, if no client is provided, the SDK will use Guzzle's default HTTP client. However, you can pass your own client that adheres to `ClientInterface`:

```
use GuzzleHttp\Client;
use Courier\CourierClient;

// Create a custom Guzzle client with specific configuration.
$client = new Client([
    'timeout' => 5.0,
]);

// Pass the custom client when creating an instance of the class.
$courier = new CourierClient(options: [
    'client' => $client
]);
```

Contributing
------------

[](#contributing)

While we value open-source contributions to this SDK, this library is generated programmatically. Additions made directly to this library would have to be moved over to our generation code, otherwise they would be overwritten upon the next generated release. Feel free to open a PR as a proof of concept, but know that we will not be able to merge it as-is. We suggest opening an issue first to discuss with us!

On the other hand, contributions to the README are always very welcome!

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance46

Moderate activity, may be stable

Popularity19

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

413d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/2528692?v=4)[Absolom](/maintainers/absmugz)[@absmugz](https://github.com/absmugz)

---

Top Contributors

[![tk26](https://avatars.githubusercontent.com/u/6154318?v=4)](https://github.com/tk26 "tk26 (30 commits)")[![DannyDouglass](https://avatars.githubusercontent.com/u/266481?v=4)](https://github.com/DannyDouglass "DannyDouglass (18 commits)")[![drew-y](https://avatars.githubusercontent.com/u/7987513?v=4)](https://github.com/drew-y "drew-y (15 commits)")[![cgradwohl](https://avatars.githubusercontent.com/u/15326707?v=4)](https://github.com/cgradwohl "cgradwohl (8 commits)")[![absmugz](https://avatars.githubusercontent.com/u/2528692?v=4)](https://github.com/absmugz "absmugz (3 commits)")[![slashequip](https://avatars.githubusercontent.com/u/2316916?v=4)](https://github.com/slashequip "slashequip (3 commits)")[![fern-api[bot]](https://avatars.githubusercontent.com/in/244756?v=4)](https://github.com/fern-api[bot] "fern-api[bot] (2 commits)")[![scarney81](https://avatars.githubusercontent.com/u/266012?v=4)](https://github.com/scarney81 "scarney81 (2 commits)")[![suhasdeshpande](https://avatars.githubusercontent.com/u/606167?v=4)](https://github.com/suhasdeshpande "suhasdeshpande (2 commits)")[![defnorep](https://avatars.githubusercontent.com/u/748373?v=4)](https://github.com/defnorep "defnorep (1 commits)")[![dsinghvi](https://avatars.githubusercontent.com/u/10870189?v=4)](https://github.com/dsinghvi "dsinghvi (1 commits)")

---

Tags

apisdkcourier

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/absmugz-courier/health.svg)

```
[![Health](https://phpackages.com/badges/absmugz-courier/health.svg)](https://phpackages.com/packages/absmugz-courier)
```

###  Alternatives

[openai-php/laravel

OpenAI PHP for Laravel is a supercharged PHP API client that allows you to interact with the Open AI API

3.7k7.6M74](/packages/openai-php-laravel)[saloonphp/saloon

Build beautiful API integrations and SDKs with Saloon

2.4k9.6M468](/packages/saloonphp-saloon)[hubspot/api-client

Hubspot API client

23914.2M16](/packages/hubspot-api-client)[php-opencloud/openstack

PHP SDK for OpenStack APIs. Supports BlockStorage, Compute, Identity, Images, Networking and Metric Gnocchi

2292.2M24](/packages/php-opencloud-openstack)[mailchimp/transactional

458.9M16](/packages/mailchimp-transactional)[resend/resend-php

Resend PHP library.

574.7M21](/packages/resend-resend-php)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
