- Deliverability Guide
- Case Studies
- Email Explained
- White Papers & Guides
- Webinars & Videos
- SparkPost vs SendGrid
- Contact Us
- Help & Docs
We are proud to announce a new release of the php-sparkpost library at version 1.0.0! After receiving feedback from the community, we have dramatically overhauled the library to be easier to use and more flexible.
One of the biggest changes that we’ve made in this release is the use of HTTP adapters. Since the library is built on top of the SparkPost REST API, one of the biggest challenges that we faced in previous versions was the ability to use our library with other libraries that also made HTTP requests. We had originally chosen to ship our client library with Guzzle, a popular HTTP request library, but this unfortunately came with the side effect of version mismatches and dependency hell for our users.
Enter HTTP adapters. HTTP adapters allow us to present the same interface to the user and allows us to use the same interface within the library for any HTTP request library or tool that the user decides to implement. The user simply has to instantiate an adapter for the library that they are using and pass it into the SparkPost constructor when they instantiate it. We use the Ivory\HttpAdapter library which is PSR-7 compliant. PSR-7 is a specification for HTTP message interfaces in PHP.
For example if you use a library like Guzzle:PHP123456use SparkPost\SparkPost;use GuzzleHttp\Client;use Ivory\HttpAdapter\Guzzle6HttpAdapter;$httpAdapter = new Guzzle6HttpAdapter(new Client());$sparky = new SparkPost($httpAdapter, 'YOUR API KEY');
Or if you’re using something like CURL:PHP1234use SparkPost\SparkPost;use Ivory\HttpAdapter\CurlHttpAdapter;$sparky = new SparkPost(new CurlHttpAdapter(), 'YOUR API KEY');
The second major change is that we switched from a static interface to an instance based one. This doesn’t change much for the end user of the library besides only needing to include one package instead of two and swapping a few ‘::’ operators for ‘->’ operators, but between this and the adapter changes mentioned above, this version isn’t a simple drop in replacement for previous versions (which is why we’re releasing as v1.0). However, as the library’s toolset grows, we hope these changes offer developers the ability to access all of its functionality from a single reference and with a shared configuration across all of those tools.
Here is a simple example of sending an email with SparkPost after setting it up above:PHP12345678$sparky->transmission->send(['from'=>'email@example.com','html'=>'<html><body><p>Testing SparkPost - the world\'s most awesomest email service!</p></body></html>','subject'=> 'Oh hey!','recipients'=>[['address'=>['email'=>'firstname.lastname@example.org']]]]);
We also added a new feature to be able to use the library to take advantage of other API endpoints that aren’t currently supported. We do this with a new ‘setupUnwrapped’ method passing in the endpoint name. Doing so exposes basic create, update, get, and delete methods which will support bodies and parameters outlined in our API documentation. This is a little hard to explain but it may be easier to see with an example:PHP12345678910111213$sparky->setupUnwrapped('templates');$templateConfig = ['name' => 'Summer Sale!','id'=>'summer-sale','content'=> ['from' => 'email@example.com','subject' => 'Summer deals','html' => '<b>Check out these deals!</b>']];$results = $sparky->templates->create($templateConfig);
The composer packagist repository for the library resides here.
It can be installed using composer:1composer require sparkpost/php-sparkpost
Please feel free to try it out in your projects. If you have feedback or would like to make a contribution please feel free to submit an issue or a pull request on the GitHub repository.
There are few – if any – apps today that could get away without utilizing email sending capabilities. At the very least, web and mobile applications need the capability to promptly send password reset links when a user forgets his or her password. Additionally, of course, users who buy something these days expect an email receipt. These transactional emails should be sent within a minute – at most. Otherwise, you risk losing users when they tire of repeatedly hitting the refresh button on their email client.
You may already know that SparkPost gives companies of all sizes the ability to send fast and dependable email. But we don’t stop there because it’s not enough to have access to the best market-leading email service if you have to become an expert to use it. We want you to be able to integrate our email service easily and efficiently, so you can get back to working on your app’s key functionality. That’s why we’ve made it our mission to make it as easy as possible for developers to integrate SparkPost into their web or mobile apps. To that end, we most recently released an SDK for Node.js.
The SparkPost team is always looking to see what SDKs would benefit our user community. Node.js has become a popular language for developers building scalable enterprise web applications, so we’ve provided a little syntactic sugar for the Node.js crowd. Using our APIs or SDKs, developers typically get up and running with SparkPost in 30 minutes or so.
Developers primarily use SparkPost SDKs to send a transmission, but we’ve included additional capabilities in the Node.js SDK:
- Recipient lists
- Sending domains
- Suppression list
These capabilities will soon be added to our PHP and Python SDKs as well. All of our SDKs are provided as open source through Github, and more will be added in the future. Send me a tweet @aydrianh if you have any new suggestions about SDKs you’d like to see.SparkPost © 2017 All Rights Reserved