PHPackages                             keneasson/php-sparkpost - 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. keneasson/php-sparkpost

ActiveLibrary[API Development](/categories/api)

keneasson/php-sparkpost
=======================

Client library for interfacing with the SparkPost API with IP Pools.

3.0.0(9y ago)029Apache 2.0PHPPHP &gt;=5.5.0

Since Nov 10Pushed 9y ago1 watchersCompare

[ Source](https://github.com/keneasson/php-sparkpost)[ Packagist](https://packagist.org/packages/keneasson/php-sparkpost)[ RSS](/packages/keneasson-php-sparkpost/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (6)Versions (16)Used By (0)

[![](https://camo.githubusercontent.com/d5c6bc65e534d09294717749ebfd210ea19c32804678375cfd92327fd5e9445e/68747470733a2f2f7777772e737061726b706f73742e636f6d2f73697465732f64656661756c742f66696c65732f6174746163686d656e74732f537061726b506f73745f4c6f676f5f322d436f6c6f725f477261792d4f72616e67655f5247422e737667)](https://www.sparkpost.com)

[Sign up](https://app.sparkpost.com/sign-up?src=Dev-Website&sfdcid=70160000000pqBb) for a SparkPost account and visit our [Developer Hub](https://developers.sparkpost.com) for even more content.

SparkPost PHP Library
=====================

[](#sparkpost-php-library)

[![Travis CI](https://camo.githubusercontent.com/f4936387fcd008dac0396602a9d32b2214863b3147726238f1b572a5a2bf261c/68747470733a2f2f7472617669732d63692e6f72672f537061726b506f73742f7068702d737061726b706f73742e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/SparkPost/php-sparkpost)[![Coverage Status](https://camo.githubusercontent.com/9a1af33f4857bd9a221bd6c70ac7811a06c75bb8d7a07c1d01cabee0b4387474/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f537061726b506f73742f7068702d737061726b706f73742f62616467652e7376673f6272616e63683d6d617374657226736572766963653d676974687562)](https://coveralls.io/github/SparkPost/php-sparkpost?branch=master) [![Slack Status](https://camo.githubusercontent.com/671cf465d03122f022428cae871a5406f9c19df4a4e6ec7424eab059c88a5ae1/687474703a2f2f736c61636b2e737061726b706f73742e636f6d2f62616467652e737667)](http://slack.sparkpost.com)

The official PHP library for using [the SparkPost REST API](https://developers.sparkpost.com).

**Note: We understand that the ivory-http-adapter we use in this library is deprecated in favor of httplug. We use Ivory internally to make it simple for you to use whatever HTTP library you want. The deprecation won't affect or limit our ongoing support of this PHP library.**

Before using this library, you must have a valid API Key. To get an API Key, please log in to your SparkPost account and generate one in the Settings page.

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

[](#installation)

The recommended way to install the SparkPost PHP Library is through composer.

```
# Install Composer
curl -sS https://getcomposer.org/installer | php

```

Next, run the Composer command to install the SparkPost PHP Library:

```
composer require sparkpost/php-sparkpost

```

After installing, you need to require Composer's autoloader:

```
require 'vendor/autoload.php';
use SparkPost\SparkPost;
```

Setting up a Request Adapter
----------------------------

[](#setting-up-a-request-adapter)

Because of dependency collision, we have opted to use a request adapter rather than requiring a request library. This means that your application will need to pass in a request adapter to the constructor of the SparkPost Library. We use the \[Ivory HTTP Adapter\] () in SparkPost. Please visit their repo for a list of supported adapters. If you don't currently use a request library, you will need to require one and create an adapter from it and pass it along. The example below uses the GuzzleHttp Client Library.

An Adapter can be setup like so:

```
use SparkPost\SparkPost;
use GuzzleHttp\Client;
use Ivory\HttpAdapter\Guzzle6HttpAdapter;

$httpAdapter = new Guzzle6HttpAdapter(new Client());
$sparky = new SparkPost($httpAdapter, ['key'=>'YOUR API KEY']);
```

Getting Started: Your First Mailing
-----------------------------------

[](#getting-started--your-first-mailing)

For this example to work as is, [Guzzle 6 will need to be installed](http://docs.guzzlephp.org/en/latest/overview.html#installation). Otherwise another adapter can be used for your specific setup. See "Setting up a Request Adapter" above.

```
require 'vendor/autoload.php';

use SparkPost\SparkPost;
use GuzzleHttp\Client;
use Ivory\HttpAdapter\Guzzle6HttpAdapter;

$httpAdapter = new Guzzle6HttpAdapter(new Client());
$sparky = new SparkPost($httpAdapter, ['key'=>'YOUR API KEY']);

try {
    // Build your email and send it!
    $results = $sparky->transmission->send([
        'from'=>[
            'name' => 'From Envelope',
            'email' => 'from@sparkpostbox.com>'
        ],
        'html'=>'Congratulations, {{name}}!You just sent your very first mailing!',
        'text'=>'Congratulations, {{name}}!! You just sent your very first mailing!',
        'substitutionData'=>['name'=>'YOUR FIRST NAME'],
        'subject'=>'First Mailing From PHP',
        'recipients'=>[
            [
                'address'=>[
                    'name'=>'YOUR FULL NAME',
                    'email'=>'YOUR EMAIL ADDRESS'
                ]
            ]
        ]
    ]);
    echo 'Woohoo! You just sent your first mailing!';
} catch (\Exception $err) {
    echo 'Whoops! Something went wrong';
    var_dump($err);
}
```

Learn More
----------

[](#learn-more)

- For more detailed examples, check our examples:
    - [Transmissions](https://github.com/SparkPost/php-sparkpost/tree/master/examples/transmission)
- Read our REST API documentation -

Field Descriptions
------------------

[](#field-descriptions)

### Transmissions

[](#transmissions)

Field NameRequired?DescriptionData TypeattachmentsnoField for attaching files - see Attachment Attributes in the [Transmssions API docs](https://developers.sparkpost.com/api/#/reference/transmissions)Array of ObjectscampaignnoField for assigning a given transmission to a specific campaign, which is a logical container for similar transmissionsStringcustomHeadersnoField for specifying additional headers to be applied to a given transmission (other than Subject, From, To, and Reply-To)Object (Simple)descriptionnoField for describing what this transmission is for the userStringfromyes\*\*Field for setting the from line of a given transmissionObjecthtmlyes\*\*Field for setting the HTML content of a given transmissionStringinlineCssnoField for enabling/disabling CSS inliningBooleaninlineImagesnoField for providing inline images - see Inline Image Attributes in the [Transmssions API docs](https://developers.sparkpost.com/api/#/reference/transmissions)Array of ObjectsmetadatanoField for adding arbitrary key/value pairs which will be included in open/click trackingObject (Simple)recipientListno\*\*Field for specifying a stored recipient list ID to be used for a given transmissionStringrecipientsyes\*\*Field for specifying who a given transmission should be sent toArray of ObjectsreplyTonoField for specifying the email address that should be used when a recipient hits the reply buttonStringrfc822no\*\*Field for setting the RFC-822 encoded content of a given transmissionStringsubjectyesField for setting the subject line of a given transmissionStringsubstitutionDatanoField for adding transmission level substitution data, which can be used in a variety of fields and in contentObject (Complex)templateno\*\*Field for specifying the Template ID of a stored template to be used when sending a given transmissionStringtextyes\*\*Field for setting the Plain Text content of a given transmissionStringtrackClicksnoField for enabling/disabling transmission level click tracking (default: true)BooleantrackOpensnoField for enabling/disabling transmission level open tracking (default: true)BooleantransactionalnoField for marking email as transactional (default: false)BooleanuseDraftTemplatenoField for allowing the sending of a transmission using a draft of a stored template (default: false)Boolean\*\* - If using inline content then html or text are required. If using RFC-822 Inline Content, then rfc822 is required. If using a stored recipient list, then recipientList is required. If using a stored template, then template is required but from is not as the values from the template will be used.

Tips and Tricks
---------------

[](#tips-and-tricks)

### General

[](#general)

- You *must* provide at least an API key when instantiating the SparkPost Library - `[ 'key'=>'184ac5480cfdd2bb2859e4476d2e5b1d2bad079bf' ]`
- The library's features are namespaced under the various SparkPost API names.

### Transmissions

[](#transmissions-1)

- If you specify a stored recipient list and inline recipients in a Transmission, you will receive an error.
- If you specify HTML and/or Plain Text content and then provide RFC-822 encoded content, you will receive an error.
    - RFC-822 content is not valid with any other content type.
- If you specify a stored template and also provide inline content via `html` or `text`, you will receive an error.
- By default, open and click tracking are enabled for a transmission.
- By default, a transmission will use the published version of a stored template.

### Contributing

[](#contributing)

See [contributing](https://github.com/SparkPost/php-sparkpost/blob/master/CONTRIBUTING.md).

###  Health Score

29

—

LowBetter than 57% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor1

Top contributor holds 64% of commits — single point of failure

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

Every ~52 days

Recently: every ~22 days

Total

14

Last Release

3566d ago

Major Versions

0.1.1 → 1.0.02015-10-14

1.2.1 → 2.0.02016-06-24

2.0.3 → 3.0.02016-09-23

PHP version history (4 changes)0.1.0PHP &gt;=5.6.1

0.1.1PHP &gt;=5.3.0

1.0.0PHP &gt;=5.5.0

2.0.2PHP ^5.5 || ^7.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/87643807?v=4)[keasson](/maintainers/keasson)[@Keasson](https://github.com/Keasson)

---

Top Contributors

[![beardyman](https://avatars.githubusercontent.com/u/4459303?v=4)](https://github.com/beardyman "beardyman (89 commits)")[![richleland](https://avatars.githubusercontent.com/u/34866?v=4)](https://github.com/richleland "richleland (23 commits)")[![j4m3s](https://avatars.githubusercontent.com/u/1998995?v=4)](https://github.com/j4m3s "j4m3s (11 commits)")[![zaporylie](https://avatars.githubusercontent.com/u/1690685?v=4)](https://github.com/zaporylie "zaporylie (5 commits)")[![jasonrhodes](https://avatars.githubusercontent.com/u/159370?v=4)](https://github.com/jasonrhodes "jasonrhodes (3 commits)")[![bdeanindy](https://avatars.githubusercontent.com/u/2376876?v=4)](https://github.com/bdeanindy "bdeanindy (2 commits)")[![yepher](https://avatars.githubusercontent.com/u/1359331?v=4)](https://github.com/yepher "yepher (2 commits)")[![lfbittencourt](https://avatars.githubusercontent.com/u/403539?v=4)](https://github.com/lfbittencourt "lfbittencourt (1 commits)")[![max-si-m](https://avatars.githubusercontent.com/u/8299599?v=4)](https://github.com/max-si-m "max-si-m (1 commits)")[![fishr01](https://avatars.githubusercontent.com/u/7548592?v=4)](https://github.com/fishr01 "fishr01 (1 commits)")[![chandon](https://avatars.githubusercontent.com/u/4522557?v=4)](https://github.com/chandon "chandon (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/keneasson-php-sparkpost/health.svg)

```
[![Health](https://phpackages.com/badges/keneasson-php-sparkpost/health.svg)](https://phpackages.com/packages/keneasson-php-sparkpost)
```

###  Alternatives

[exsyst/swagger

A php library to manipulate Swagger specifications

35816.3M7](/packages/exsyst-swagger)[hubspot/api-client

Hubspot API client

24015.5M18](/packages/hubspot-api-client)[pocketmine/bedrock-protocol

An implementation of the Minecraft: Bedrock Edition protocol in PHP

172437.8k11](/packages/pocketmine-bedrock-protocol)[botman/driver-telegram

Telegram driver for BotMan

94452.6k6](/packages/botman-driver-telegram)

PHPackages © 2026

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