2017 © Pedro Peláez
 

library sendgrid

This library allows you to quickly and easily send emails through SendGrid using PHP.

image

sendgrid/sendgrid

This library allows you to quickly and easily send emails through SendGrid using PHP.

  • Wednesday, June 27, 2018
  • by eddiezane
  • Repository
  • 239 Watchers
  • 857 Stars
  • 3,632,705 Installations
  • PHP
  • 85 Dependents
  • 7 Suggesters
  • 433 Forks
  • 88 Open issues
  • 76 Versions
  • 9 % Grown

The README.md

SendGrid Logo, (*1)

BuildStatus Packagist Downloads MIT licensed Twitter Follow GitHub contributors Open Source Helpers, (*2)

NEW:, (*3)

  • Send SMS messages with Twilio.

This library allows you to quickly and easily use the Twilio SendGrid Web API v3 via PHP., (*4)

Version 7.X.X of this library provides full support for all Twilio SendGrid Web API v3 endpoints, including the new v3 /mail/send., (*5)

If you need support using SendGrid, please check the Twilio SendGrid Support Help Center., (*6)

Please browse the rest of this README for further details., (*7)

We appreciate your continued support, thank you!, (*8)

Table of Contents

, (*9)

Installation

Prerequisites

  • PHP version 7.3, 7.4, 8.0, or 8.1
  • The Twilio SendGrid service, starting at the free level to send up to 40,000 emails for the first 30 days, then send 100 emails/day free forever or check out our pricing.
  • For SMS messages, you will need a free Twilio account.

Setup Environment Variables

Update the development environment with your SENDGRID_API_KEY, for example:, (*10)

  1. Copy the sample env file to a new file named .env
cp .env.sample .env
  1. Edit the .env file to include your SENDGRID_API_KEY
  2. Source the .env file
source ./.env

Install Package

Add Twilio SendGrid to your composer.json file. If you are not using Composer, we highly recommend it. It's an excellent way to manage dependencies in your PHP application., (*11)

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

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., (*12)

⬇︎ Download Packaged Library ⬇︎, (*13)

Previous versions of the library can be downloaded directly from GitHub., (*14)

Dependencies

, (*15)

Quick Start

Include the proper lines from below at the top of each example based on your installation method:, (*16)

<?php
// Uncomment the next line if you're using a dependency loader (such as Composer) (recommended)
// require 'vendor/autoload.php';

// Uncomment the next line if you're not using a dependency loader (such as Composer), replacing <PATH TO> with the path to the sendgrid-php.php file
// require_once '<PATH TO>/sendgrid-php.php';

Hello Email

The following is the minimum needed code to send an email. You may find more examples in our USE_CASES file:, (*17)

$email = new \SendGrid\Mail\Mail();
$email->setFrom("test@example.com", "Example User");
$email->setSubject("Sending with Twilio SendGrid is Fun");
$email->addTo("test@example.com", "Example User");
$email->addContent("text/plain", "and easy to do anywhere, even with PHP");
$email->addContent(
    "text/html", "<strong>and easy to do anywhere, even with PHP</strong>"
);
$sendgrid = new \SendGrid(getenv('SENDGRID_API_KEY'));
try {
    $response = $sendgrid->send($email);
    print $response->statusCode() . "\n";
    print_r($response->headers());
    print $response->body() . "\n";
} catch (Exception $e) {
    echo 'Caught exception: '. $e->getMessage() ."\n";
}

The SendGrid\Mail constructor creates a personalization object for you. Here is an example of how to add to it., (*18)

General v3 Web API Usage (With Fluent Interface)

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

try {
    $response = $sg->client->suppression()->bounces()->get();
    print $response->statusCode() . "\n";
    print_r($response->headers());
    print $response->body() . "\n";
} catch (Exception $e) {
    echo 'Caught exception: '.  $e->getMessage(). "\n";
}

General v3 Web API Usage (Without Fluent Interface)

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

try {
    $response = $sg->client->_("suppression/bounces")->get();
    print $response->statusCode() . "\n";
    print_r($response->headers());
    print $response->body() . "\n";
} catch (Exception $e) {
    echo 'Caught exception: '.  $e->getMessage(). "\n";
}

, (*19)

Use Cases

Examples of common API use cases, such as how to send an email with a transactional template., (*20)

, (*21)

Usage

, (*22)

Announcements

v7 has been released! Please see the release notes for details., (*23)

All updates to this library are documented in our CHANGELOG and releases., (*24)

, (*25)

How to Contribute

We encourage contribution to our libraries (you might even score some nifty swag), please see our CONTRIBUTING guide for details., (*26)

Quick links:, (*27)

, (*28)

Troubleshooting

Please see our troubleshooting guide for common library issues., (*29)

, (*30)

About

sendgrid-php is maintained and funded by Twilio SendGrid, Inc. The names and logos for sendgrid-php are trademarks of Twilio SendGrid, Inc., (*31)

, (*32)

Support

For product support, please check the Twilio SendGrid Support Help Center., (*33)

License

The MIT License (MIT), (*34)

The Versions

27/06 2018

dev-master

9999999-dev http://github.com/sendgrid/sendgrid-php

This library allows you to quickly and easily send emails through SendGrid using PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

email grid sendgrid send

19/05 2018

7.0.0

7.0.0.0 http://github.com/sendgrid/sendgrid-php

This library allows you to quickly and easily send emails through SendGrid using PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

email grid sendgrid send

19/05 2018

v7.x-dev

7.9999999.9999999.9999999-dev http://github.com/sendgrid/sendgrid-php

This library allows you to quickly and easily send emails through SendGrid using PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

email grid sendgrid send

29/03 2018

6.2.0

6.2.0.0 http://github.com/sendgrid/sendgrid-php

This library allows you to quickly and easily send emails through SendGrid using PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

email grid sendgrid send

28/03 2018

6.1.0

6.1.0.0 http://github.com/sendgrid/sendgrid-php

This library allows you to quickly and easily send emails through SendGrid using PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

email grid sendgrid send

23/03 2018

dev-fix_unit_tests

dev-fix_unit_tests http://github.com/sendgrid/sendgrid-php

This library allows you to quickly and easily send emails through SendGrid using PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

email grid sendgrid send

21/12 2017

dev-example-heroku-hello-email

dev-example-heroku-hello-email

  Sources   Download

MIT

The Requires

 

The Development Requires

email grid sendgrid send

01/07 2017

6.0.0

6.0.0.0 http://github.com/sendgrid/sendgrid-php

This library allows you to quickly and easily send emails through SendGrid using PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

email grid sendgrid send

30/06 2017

5.6.2

5.6.2.0 http://github.com/sendgrid/sendgrid-php

This library allows you to quickly and easily send emails through SendGrid using PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

email grid sendgrid send

27/06 2017

5.6.1

5.6.1.0 http://github.com/sendgrid/sendgrid-php

This library allows you to quickly and easily send emails through SendGrid using PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

email grid sendgrid send

27/06 2017

5.6

5.6.0.0 http://github.com/sendgrid/sendgrid-php

This library allows you to quickly and easily send emails through SendGrid using PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

email grid sendgrid send

20/06 2017

dev-hello_world_test

dev-hello_world_test http://github.com/sendgrid/sendgrid-php

This library allows you to quickly and easily send emails through SendGrid using PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

email grid sendgrid send

18/05 2017

5.5.1

5.5.1.0 http://github.com/sendgrid/sendgrid-php

This library allows you to quickly and easily send emails through SendGrid using PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

email grid sendgrid send

05/05 2017

5.5.0

5.5.0.0 http://github.com/sendgrid/sendgrid-php

This library allows you to quickly and easily send emails through SendGrid using PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

email grid sendgrid send

05/05 2017

dev-dependency-update

dev-dependency-update http://github.com/sendgrid/sendgrid-php

This library allows you to quickly and easily send emails through SendGrid using PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

email grid sendgrid send

18/04 2017

5.4.2

5.4.2.0 http://github.com/sendgrid/sendgrid-php

This library allows you to quickly and easily send emails through SendGrid using PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

email grid sendgrid send

04/04 2017

5.4.1

5.4.1.0 http://github.com/sendgrid/sendgrid-php

This library allows you to quickly and easily send emails through SendGrid using PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

email grid sendgrid send

16/03 2017

5.4.0

5.4.0.0 http://github.com/sendgrid/sendgrid-php

This library allows you to quickly and easily send emails through SendGrid using PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

email grid sendgrid send

15/03 2017

5.3.0

5.3.0.0 http://github.com/sendgrid/sendgrid-php

This library allows you to quickly and easily send emails through SendGrid using PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

email grid sendgrid send

04/03 2017

5.2.3

5.2.3.0 http://github.com/sendgrid/sendgrid-php

This library allows you to quickly and easily send emails through SendGrid using PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

email grid sendgrid send

04/03 2017

5.2.2

5.2.2.0 http://github.com/sendgrid/sendgrid-php

This library allows you to quickly and easily send emails through SendGrid using PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

email grid sendgrid send

01/03 2017

5.2.1

5.2.1.0 http://github.com/sendgrid/sendgrid-php

This library allows you to quickly and easily send emails through SendGrid using PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

email grid sendgrid send

24/02 2017

5.2.0

5.2.0.0 http://github.com/sendgrid/sendgrid-php

This library allows you to quickly and easily send emails through SendGrid using PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

email grid sendgrid send

18/11 2016

5.1.2

5.1.2.0 http://github.com/sendgrid/sendgrid-php

This library allows you to quickly and easily send emails through SendGrid using PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

email grid sendgrid send

17/11 2016

dev-update-dependency

dev-update-dependency http://github.com/sendgrid/sendgrid-php

This library allows you to quickly and easily send emails through SendGrid using PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

email grid sendgrid send

11/10 2016

5.1.1

5.1.1.0 http://github.com/sendgrid/sendgrid-php

This library allows you to quickly and easily send emails through SendGrid using PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

email grid sendgrid send

29/09 2016

5.1.0

5.1.0.0 http://github.com/sendgrid/sendgrid-php

This library allows you to quickly and easily send emails through SendGrid using PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

email grid sendgrid send

13/09 2016

dev-inbound

dev-inbound http://github.com/sendgrid/sendgrid-php

This library allows you to quickly and easily send emails through SendGrid using PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

email grid sendgrid send

13/09 2016

dev-mail

dev-mail http://github.com/sendgrid/sendgrid-php

This library allows you to quickly and easily send emails through SendGrid using PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

email grid sendgrid send

13/09 2016

5.0.9

5.0.9.0 http://github.com/sendgrid/sendgrid-php

This library allows you to quickly and easily send emails through SendGrid using PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

email grid sendgrid send

24/08 2016

5.0.8

5.0.8.0 http://github.com/sendgrid/sendgrid-php

This library allows you to quickly and easily send emails through SendGrid using PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

email grid sendgrid send

24/08 2016

dev-toc-template

dev-toc-template http://github.com/sendgrid/sendgrid-php

This library allows you to quickly and easily send emails through SendGrid using PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

email grid sendgrid send

26/07 2016

5.0.7

5.0.7.0 http://github.com/sendgrid/sendgrid-php

This library allows you to quickly and easily send emails through SendGrid using PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

email grid sendgrid send

26/07 2016

dev-troubleshooting

dev-troubleshooting http://github.com/sendgrid/sendgrid-php

This library allows you to quickly and easily send emails through SendGrid using PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

email grid sendgrid send

20/07 2016

5.0.6

5.0.6.0 http://github.com/sendgrid/sendgrid-php

This library allows you to quickly and easily send emails through SendGrid using PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

email grid sendgrid send

20/07 2016

dev-documentation-updates

dev-documentation-updates http://github.com/sendgrid/sendgrid-php

This library allows you to quickly and easily send emails through SendGrid using PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

email grid sendgrid send

08/07 2016

5.0.4

5.0.4.0 http://github.com/sendgrid/sendgrid-php

This library allows you to quickly and easily send emails through SendGrid using PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

email grid sendgrid send

08/07 2016

dev-prism

dev-prism http://github.com/sendgrid/sendgrid-php

This library allows you to quickly and easily send emails through SendGrid using PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

email grid sendgrid send

05/07 2016

5.0.3

5.0.3.0 http://github.com/sendgrid/sendgrid-php

This library allows you to quickly and easily send emails through SendGrid using PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

email grid sendgrid send

18/06 2016

5.0.1

5.0.1.0 http://github.com/sendgrid/sendgrid-php

This library allows you to quickly and easily send emails through SendGrid using PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

email grid sendgrid send

14/06 2016

5.0.0

5.0.0.0 http://github.com/sendgrid/sendgrid-php

This library allows you to quickly and easily send emails through SendGrid using PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

email grid sendgrid send

18/02 2016

4.0.4

4.0.4.0 http://github.com/sendgrid/sendgrid-php

This library allows you to quickly and easily send emails through SendGrid using PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

email grid sendgrid send

15/12 2015

4.0.2

4.0.2.0 http://github.com/sendgrid/sendgrid-php

This library allows you to quickly and easily send emails through SendGrid using PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

email grid sendgrid send

04/12 2015

4.0.1

4.0.1.0 http://github.com/sendgrid/sendgrid-php

This library allows you to quickly and easily send emails through SendGrid using PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

email grid sendgrid send

17/10 2015

4.0.0

4.0.0.0 http://github.com/sendgrid/sendgrid-php

This library allows you to quickly and easily send emails through SendGrid using PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

email grid sendgrid send

13/05 2015

3.2.0

3.2.0.0 http://github.com/sendgrid/sendgrid-php

This library allows you to quickly and easily send emails through SendGrid using PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

email grid sendgrid send

27/04 2015

3.1.0

3.1.0.0 http://github.com/sendgrid/sendgrid-php

This library allows you to quickly and easily send emails through SendGrid using PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

email grid sendgrid send

14/04 2015

3.0.0

3.0.0.0 http://github.com/sendgrid/sendgrid-php

This library allows you to quickly and easily send emails through SendGrid using PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

email grid sendgrid send

29/01 2015

2.2.1

2.2.1.0 http://github.com/sendgrid/sendgrid-php

This library allows you to quickly and easily send emails through SendGrid using PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

email grid sendgrid send

12/01 2015

2.2.0

2.2.0.0 http://github.com/sendgrid/sendgrid-php

This library allows you to quickly and easily send emails through SendGrid using PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

email grid sendgrid send

17/07 2014

2.1.1

2.1.1.0 http://github.com/sendgrid/sendgrid-php

This library allows you to quickly and easily send emails through SendGrid using PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

email grid sendgrid send

10/07 2014

2.1.0

2.1.0.0 http://github.com/sendgrid/sendgrid-php

This library allows you to quickly and easily send emails through SendGrid using PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

email grid sendgrid send

16/06 2014

2.0.6

2.0.6.0 http://github.com/sendgrid/sendgrid-php

This library allows you to quickly and easily send emails through SendGrid using PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

email grid sendgrid send

18/04 2014

2.0.5

2.0.5.0 http://github.com/sendgrid/sendgrid-php

This library allows you to quickly and easily send emails through SendGrid using PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

email grid sendgrid send

29/03 2014

2.0.4

2.0.4.0 http://github.com/sendgrid/sendgrid-php

This library allows you to quickly and easily send emails through SendGrid using PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

email grid sendgrid send

22/02 2014

2.0.3

2.0.3.0 http://github.com/sendgrid/sendgrid-php

This library allows you to quickly and easily send emails through SendGrid using PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

email grid sendgrid send

20/02 2014

2.0.2

2.0.2.0 http://github.com/sendgrid/sendgrid-php

This library allows you to quickly and easily send emails through SendGrid using PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

email grid sendgrid send

17/02 2014

2.0.1

2.0.1.0 http://github.com/sendgrid/sendgrid-php

This library allows you to quickly and easily send emails through SendGrid using PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

email grid sendgrid send

08/01 2014

1.1.7

1.1.7.0 http://github.com/sendgrid/sendgrid-php

This library allows you to quickly and easily send emails through SendGrid using PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

email grid sendgrid send

11/12 2013

1.1.6

1.1.6.0 http://github.com/sendgrid/sendgrid-php

This library allows you to quickly and easily send emails through SendGrid using PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

email grid sendgrid send

05/11 2013

1.1.5

1.1.5.0 http://github.com/sendgrid/sendgrid-php

This library allows you to quickly and easily send emails through SendGrid using PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

email grid sendgrid send

04/11 2013

1.1.4

1.1.4.0 http://github.com/sendgrid/sendgrid-php

This library allows you to quickly and easily send emails through SendGrid using PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

email grid sendgrid send

03/11 2013

1.1.3

1.1.3.0 http://github.com/sendgrid/sendgrid-php

This library allows you to quickly and easily send emails through SendGrid using PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

email grid sendgrid send

03/11 2013

1.1.2

1.1.2.0 http://github.com/sendgrid/sendgrid-php

This library allows you to quickly and easily send emails through SendGrid using PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

email grid sendgrid send

03/11 2013

1.1.1

1.1.1.0 http://github.com/sendgrid/sendgrid-php

This library allows you to quickly and easily send emails through SendGrid using PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

email grid sendgrid send

03/11 2013

1.1.0

1.1.0.0 http://github.com/sendgrid/sendgrid-php

This library allows you to quickly and easily send emails through SendGrid using PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

email grid sendgrid send

18/09 2013

1.0.9

1.0.9.0 http://sendgrid.com

This library allows you to quickly and easily send emails through SendGrid using PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

02/09 2013

1.0.8

1.0.8.0 http://sendgrid.com

This library allows you to quickly and easily send emails through SendGrid using PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

01/09 2013

1.0.7

1.0.7.0 http://sendgrid.com

This library allows you to quickly and easily send emails through SendGrid using PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

01/09 2013

1.0.6

1.0.6.0 http://sendgrid.com

This library allows you to quickly and easily send emails through SendGrid using PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

09/08 2013

1.0.5

1.0.5.0 http://sendgrid.com

This library allows you to quickly and easily send emails through SendGrid using PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

29/07 2013

1.0.4

1.0.4.0 http://sendgrid.com

This library allows you to quickly and easily send emails through SendGrid using PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

09/07 2013

1.0.3

1.0.3.0 http://sendgrid.com

This library allows you to quickly and easily send emails through SendGrid using PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

08/07 2013

1.0.2

1.0.2.0 http://sendgrid.com

This library allows you to quickly and easily send emails through SendGrid using PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

08/07 2013

1.0.1

1.0.1.0 http://sendgrid.com

This library allows you to quickly and easily send emails through SendGrid using PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

03/04 2013

1.0.0

1.0.0.0 http://sendgrid.com

This library allows you to quickly and easily send emails through SendGrid using PHP.

  Sources   Download

MIT

The Requires