Skip to content
SendGrid PHP helper library.
PHP Shell
Latest commit a1153ef Jun 19, 2016 @thinkingserious thinkingserious committed on GitHub Update README.md

README.md

BuildStatus

This library allows you to quickly and easily use the SendGrid Web API via PHP.

Announcements

BREAKING CHANGE as of 2016.06.14

Version 5.0.0 is a breaking change for the entire library.

Version 5.0.0 brings you full support for all Web API v3 endpoints. We have the following resources to get you started quickly:

Thank you for your continued support!

All updates to this library is documented in our CHANGELOG.

Installation

Setup Environment Variables

First, get your free SendGrid account here.

Next, update your environment with your SENDGRID_API_KEY.

echo "export SENDGRID_API_KEY='YOUR_API_KEY'" > sendgrid.env
echo "sendgrid.env" >> .gitignore
source ./sendgrid.env

Install Package

Add SendGrid to your composer.json file. If you are not using Composer, you should be. It's an excellent way to manage dependencies in your PHP application.

{
  "require": {
    "sendgrid/sendgrid": "~5.0"
  }
}

Then at the top of your PHP script require the autoloader:

require 'vendor/autoload.php';

Alternative: Install package from zip

If you are not using Composer, simply download and install the latest packaged release of the library as a zip.

⬇︎ Download Packaged Library ⬇︎

Then require the library from package:

require("path/to/sendgrid-php/sendgrid-php.php");

Previous versions of the library can be found in the version index.

Dependencies

Quick Start

Hello Email

<?php
// If you are using Composer
require 'vendor/autoload.php';

// If you are not using Composer (recommended)
// require("path/to/sendgrid-php/sendgrid-php.php");

$from = new SendGrid\Email(null, "test@example.com");
$subject = "Hello World from the SendGrid PHP Library";
$to = new SendGrid\Email(null, "test@example.com");
$content = new SendGrid\Content("text/plain", "some text here");
$mail = new SendGrid\Mail($from, $subject, $to, $content);

$apiKey = getenv('SENDGRID_API_KEY');
$sg = new \SendGrid($apiKey);

$response = $sg->client->mail()->send()->post($mail);
echo $response->statusCode();
echo $response->headers();
echo $response->body();

General v3 Web API Usage

<?php
// If you are using Composer (recommended)
require 'vendor/autoload.php';

// If you are not using Composer
// require("path/to/sendgrid-php/sendgrid-php.php");

$apiKey = getenv('SENDGRID_API_KEY');
$sg = new \SendGrid($apiKey);

$response = $sg->client->api_keys()->get();

print $response->statusCode();
print $response->headers();
print $response->body();

Usage

Roadmap

If you are intersted in the future direction of this project, please take a look at our milestones. We would love to hear your feedback.

How to Contribute

We encourage contribution to our libraries, please see our CONTRIBUTING guide for details.

Quick links:

About

sendgrid-php is guided and supported by the SendGrid Developer Experience Team.

sendgrid-php is maintained and funded by SendGrid, Inc. The names and logos for sendgrid-php are trademarks of SendGrid, Inc.

SendGrid Logo

Something went wrong with that request. Please try again.