PHP Frameworks In The Wild: A Closer Look at the PHP Ecosystem

Avi Goldman
Aug. 4, 2017 by Avi Goldman

SparkPost and PHP Frameworks: Scratching the Surface

PHP is one of the older languages used on the Web, created in the mid-nineties. Some environments are still stuck running PHP 3 while others are running the latest version. There’s been a lot of development around amazing PHP frameworks and tools in the last few years, and most of them come with easy ways to send mail. We recently broke down how we simplified our PHP library, but going with a native solution can still be easier sometimes. Here’s a quick breakdown of how to use SparkPost to send mail with some of the more popular PHP frameworks in the wild.

Plain ol’ PHP

Sometimes you just need to fire off a quick API call. All you need is a little cURL magic to do what you need. Check out this snippet for shooting off SparkPost requests.

🐘 + 🎶 = ❤️

Here at SparkPost we created a composer package to simplify using our API in all modern PHP environments. It’s quick to install and provides some “sugar” to smooth out some of the more confusing parts of the API. To keep our library as flexible as possible, we use PHP HTTP to let you bring your own request library. To use it we can require guzzlehttp/guzzle, the php-http/guzzle6-adapter, and the sparkpost/sparkpost library. Then we are good to go with the code below.

World of WordPress

Our very own Raju wrote a SparkPost plugin to use SparkPost as your email provider. It exposes key features like using templates, sending via SMTP or the API, and allows you to hook in at a ton of points to modify the email and settings on the fly. Plus, it’s easy to get started 😎

PHPMailer

PHPMailer is probably the most popular way to send mail in PHP! It’s got a great API that makes it easy to plug any SMTP provider. Check out this simple example to get started with SparkPost quickly.

Laravel

Laravel is a whole beast unto itself so I’ll just hit the main points. You can follow the official Laravel docs to get set up with the SparkPost mail driver. Once you’ve done that you can generate and send your mailables. Matt Stauffer did a solid write up on using SparkPost with Laravel which is worth checking out.

CodeIgniter

CodeIgniter provides a simple API to send mail. You can add the SMTP configuration in code or through config/email.php. Check out the example below to fire off a quick email.

Be sure to comment below or tweet us if you want us to go into more depth on any particular tool or if we missed your favorite framework 👋

—Avi, Software Engineer
@theavigoldman

10 Steps Great Deliverability Blog Footer

Related Content

How And Why We Simplified The SparkPost PHP Client Library

Introducing our PHP 2.0 Library. Check out the changes we’ve made to keep up with the complex areas of our API additions for our PHP client library users.

read more

SparkPost Client Libraries: Oh The Places You'll Go!

SparkPost's client libraries allow you to access our API in a native-to-them programming language. Easy peasy, lemon squeezy!

read more

Tracking Recipient Preferences With The User Agent Header in PHP

Learn how to build out a webhook service to receive, process, and store user agent details for tracking clicks from your SparkPost account.

read more

Start sending email in minutes!

The world’s most powerful email delivery solution is now yours in a developer-friendly, quick to set up cloud service. Open a SparkPost account today and get started for free.

Get Started

Send this to a friend