Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
SendGrid (http://sendgrid.com) PHP helper library.
PHP Shell

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
SendGrid
Test
examples
lib/swift
.gitignore
README.md
SendGrid.php
SendGrid_loader.php

README.md

sendgrid-php

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

License

Licensed under the MIT License.

Install

git clone git@github.com:sendgrid/sendgrid-php.git

SendGrid APIs

SendGrid provides two methods of sending email: the Web API, and SMTP API. SendGrid recommends using the SMTP API for sending emails. For an explanation of the benefits of each, refer to http://docs.sendgrid.com/documentation/get-started/integrate/examples/smtp-vs-rest/.

This library implements a common interface to make it very easy to use either API.

Mail Pre-Usage

Before we begin using the library, its important to understand a few things about the library architecture...

  • The SendGrid Mail object is the means of setting mail data. In general, data can be set in three ways for most elements:

    1. set - reset the data, and initialize it to the given element. This will destroy previous data
    2. set (List) - for array based elements, we provide a way of passing the entire array in at once. This will also destroy previous data.
    3. add - append data to the list of elements.
  • Sending an email is as simple as :

    1. Creating a SendGrid Instance
    2. Creating a SendGrid Mail object, and setting its data
    3. Sending the mail using either SMTP API or Web API.

Mail Usage

To begin using this library, you must first include it

include 'path/to/sendgrid-php/SendGrid_loader.php';

Then, initialize the SendGrid object with your SendGrid credentials

$sendgrid = new SendGrid('username', 'password');

Create a new SendGrid Mail object and add your message details

$mail = new SendGrid\Mail();
$mail->addTo('foo@bar.com')->
       setFrom('me@bar.com')->
       setSubject('Subject goes here')->
       setText('Hello World!')->
       setHtml('<strong>Hello World!</strong>');

Send it using the API of your choice (SMTP or Web)

$sendgrid->smtp->send($mail);

Or

$sendgrid->web->send($mail);
Something went wrong with that request. Please try again.