PHPackages                             mailjet/mailjet-apiv3-php - 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. [Mail &amp; Notifications](/categories/mail)
4. /
5. mailjet/mailjet-apiv3-php

ActiveLibrary[Mail &amp; Notifications](/categories/mail)

mailjet/mailjet-apiv3-php
=========================

PHP wrapper for the Mailjet API

v1.6.6(4mo ago)27411.4M—3.3%9220MITPHPPHP ^8.1CI failing

Since May 25Pushed 2mo ago27 watchersCompare

[ Source](https://github.com/mailjet/mailjet-apiv3-php)[ Packagist](https://packagist.org/packages/mailjet/mailjet-apiv3-php)[ Docs](https://github.com/mailjet/mailjet-apiv3-php/)[ RSS](/packages/mailjet-mailjet-apiv3-php/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (9)Versions (37)Used By (20)

[![alt text](https://camo.githubusercontent.com/e0ba8a283113ae3c7f2ef84660c832c21b3928d15d14981a39352addc123845f/68747470733a2f2f7777772e6d61696c6a65742e636f6d2f696d616765732f656d61696c2f7472616e7361632f6c6f676f5f6865616465722e706e67 "Mailjet")](https://camo.githubusercontent.com/e0ba8a283113ae3c7f2ef84660c832c21b3928d15d14981a39352addc123845f/68747470733a2f2f7777772e6d61696c6a65742e636f6d2f696d616765732f656d61696c2f7472616e7361632f6c6f676f5f6865616465722e706e67)

Official Mailjet PHP Wrapper
============================

[](#official-mailjet-php-wrapper)

[![Build Status](https://camo.githubusercontent.com/09193bfea5158cbf116031666ec9b9961137635d97fa34ec77828d6083452026/68747470733a2f2f7472617669732d63692e6f72672f6d61696c6a65742f6d61696c6a65742d61706976332d7068702e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/mailjet/mailjet-apiv3-php)[![MIT License](https://camo.githubusercontent.com/48593de0035d3aebc555d81be22bb1136d0741866cc69614fd437cacc7553cf7/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d3030374543372e7376673f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/48593de0035d3aebc555d81be22bb1136d0741866cc69614fd437cacc7553cf7/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d3030374543372e7376673f7374796c653d666c61742d737175617265)[![Current Version](https://camo.githubusercontent.com/880e4225d1236971a3197ed92be4bc139b69167c6524ce040cb798bca7777dad/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f76657273696f6e2d322e302e302d677265656e2e737667)](https://camo.githubusercontent.com/880e4225d1236971a3197ed92be4bc139b69167c6524ce040cb798bca7777dad/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f76657273696f6e2d322e302e302d677265656e2e737667)

Overview
--------

[](#overview)

This repository contains the official PHP wrapper for the Mailjet API.

Check out all the resources and PHP code examples in the [Offical Documentation](https://dev.mailjet.com/guides/?php#getting-started).

Table of contents
-----------------

[](#table-of-contents)

- [Compatibility](#compatibility)
- [Installation](#installation)
- [Authentication](#authentication)
- [Make your first call](#make-your-first-call)
- [Client / Call configuration specifics](#client--call-configuration-specifics)
    - [Options](#options)
        - [API versioning](#api-versioning)
        - [Base URL](#base-url)
    - [Disable API call](#disable-api-call)
- [List of resources](#list-of-resources)
- [Request examples](#request-examples)
    - [POST request](#post-request)
        - [Simple POST request](#simple-post-request)
        - [Using actions](#using-actions)
    - [GET request](#get-request)
        - [Retrieve all objects](#retrieve-all-objects)
        - [Use filtering](#use-filtering)
        - [Retrieve a single object](#retrieve-a-single-object)
    - [PUT request](#put-request)
    - [DELETE request](#delete-request)
    - [Response](#response)
    - [API resources helpers](#api-resources-helpers)
- [SMS API](#sms-api)
    - [Token authentication](#token-authentication)
    - [Example Request](#example-request)
- [Contribute](#contribute)

### Compatibility

[](#compatibility)

This library requires **PHP v8.1** or higher.

### Installation

[](#installation)

Use the below code to install the wrapper:

```
composer require mailjet/mailjet-apiv3-php
```

This library requires a [PSR-18](https://www.php-fig.org/psr/psr-18/) HTTP client and [PSR-17](https://www.php-fig.org/psr/psr-17/) factories. If you don't already have one in your project, Composer will auto-install a compatible default (e.g. Guzzle) via [php-http/discovery](https://github.com/php-http/discovery).

If you prefer a specific HTTP client, require it explicitly:

```
# Using Guzzle
composer require guzzlehttp/guzzle

# Using Symfony HttpClient
composer require symfony/http-client nyholm/psr7
```

### Bring Your Own HTTP Client

[](#bring-your-own-http-client)

You can inject your own PSR-18 HTTP client into the Mailjet client:

```
use \Mailjet\Client;

// Auto-discovery (default) — uses whatever PSR-18 client is installed
$mj = new Client($apikey, $apisecret);

// Inject a specific HTTP client
$httpClient = new \GuzzleHttp\Client(['timeout' => 30, 'proxy' => 'tcp://localhost:8080']);
$mj = new Client($apikey, $apisecret, true, [], $httpClient);

// Inject a Symfony HttpClient
$httpClient = new \Symfony\Component\HttpClient\Psr18Client();
$mj = new Client($apikey, $apisecret, true, [], $httpClient);
```

You can also inject PSR-17 request and stream factories as the 6th and 7th constructor arguments if needed.

### Authentication

[](#authentication)

The Mailjet Email API uses your API and Secret keys for authentication. [Grab](https://app.mailjet.com/account/apikeys) and save your Mailjet API credentials.

```
export MJ_APIKEY_PUBLIC='your API key'
export MJ_APIKEY_PRIVATE='your API secret'
```

> Note: For the SMS API the authorization is based on a Bearer token. See information about it in the [SMS API](#sms-api) section of the readme.

Initialize your [Mailjet](http://www.mailjet.com) Client:

```
use \Mailjet\Resources;

// getenv will allow us to get the MJ_APIKEY_PUBLIC/PRIVATE variables we created before:

$apikey = getenv('MJ_APIKEY_PUBLIC');
$apisecret = getenv('MJ_APIKEY_PRIVATE');

$mj = new \Mailjet\Client($apikey, $apisecret);

// or, without using environment variables:

$apikey = 'your API key';
$apisecret = 'your API secret';

$mj = new \Mailjet\Client($apikey, $apisecret);
```

### Make your first call

[](#make-your-first-call)

Here's an example on how to send an email:

```
