PHPackages                             tony13tv/silverstripe-sendgrid - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Mail &amp; Notifications](/categories/mail)
4. /
5. tony13tv/silverstripe-sendgrid

ActiveSilverstripe-module[Mail &amp; Notifications](/categories/mail)

tony13tv/silverstripe-sendgrid
==============================

Sendgrid integration with Silverstripe Forked from sendgrid/sendgrid

12811PHP

Since Oct 3Pushed 9y ago1 watchersCompare

[ Source](https://github.com/tony13tv/silverstripe-sendgrid-integration)[ Packagist](https://packagist.org/packages/tony13tv/silverstripe-sendgrid)[ RSS](/packages/tony13tv-silverstripe-sendgrid/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

Sendgrid-php
============

[](#sendgrid-php)

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

Important: This library requires PHP 5.3 or higher.

[![BuildStatus](https://camo.githubusercontent.com/b3d1fafb543446232b518c518c741ec4e9d4d25f470aa9e2184e3d85236af652/68747470733a2f2f7472617669732d63692e6f72672f73656e64677269642f73656e64677269642d7068702e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/sendgrid/sendgrid-php)[![Latest Stable Version](https://camo.githubusercontent.com/695b93a075eed8b0b0f00b14af899f578c32d7e076afd4eebf21a15d36c3dc6a/68747470733a2f2f706f7365722e707567782e6f72672f73656e64677269642f73656e64677269642f76657273696f6e2e706e67)](https://packagist.org/packages/sendgrid/sendgrid)

```
$sendgrid = new SendGrid('username', 'password');
$email    = new SendGrid\Email();
$email->addTo('foo@bar.com')->
       addTo('dude@bar.com')->
       setFrom('me@bar.com')->
       setSubject('Subject goes here')->
       setText('Hello World!')->
       setHtml('Hello World!');

$sendgrid->web->send($email);
```

Installation
------------

[](#installation)

Add SendGrid to your `composer.json` file. If you are not using [Composer](http://getcomposer.org), you should be. It's an excellent way to manage dependencies in your PHP application.

```
{
  "minimum-stability" : "dev",
  "require": {
    "sendgrid/sendgrid": "1.1.7"
  }
}
```

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

```
require 'vendor/autoload.php';
```

#### Alternative: Install source from GitHub

[](#alternative-install-source-from-github)

If you don't want to use Composer, you can install from source.

```
git clone https://github.com/Mashape/unirest-php.git
git clone https://github.com/sendgrid/sendgrid-php.git
```

And include it in your PHP script:

```
require_once '/path/to/unirest-php/lib/Unirest.php';
require_once '/path/to/sendgrid-php/lib/SendGrid.php';
SendGrid::register_autoloader();
```

#### Optional

[](#optional)

IF using the `smtp` option, you need [swiftmailer](https://github.com/swiftmailer/swiftmailer). This is not necessary if using the web API approach.

```
git clone git://github.com/swiftmailer/swiftmailer.git
ln -s swiftmailer/lib/swift_required.php swift_required.php
```

SendGrid APIs
-------------

[](#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 .

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

Example App
-----------

[](#example-app)

There is a [sendgrid-php-example app](https://github.com/scottmotte/sendgrid-php-example) to help jumpstart your development.

Usage
-----

[](#usage)

To begin using this library, initialize the SendGrid object with your SendGrid credentials.

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

Create a new SendGrid Email object and add your message details.

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

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

```
$sendgrid->web->send($mail);
```

Or

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

### addTo

[](#addto)

You can add one or multiple TO addresses using `addTo`.

```
$mail = new SendGrid\Email();
$mail->addTo('foo@bar.com')->
       addTo('another@another.com');
$sendgrid->web->send($mail);
```

### setTos

[](#settos)

If you prefer, you can add multiple TO addresses as an array using the `setTos` method. This will unset any previous `addTo`s you appended.

```
$mail   = new SendGrid\Email();
$emails = array("foo@bar.com", "another@another.com", "other@other.com");
$mail->setTos($emails);
$sendgrid->web->send($mail);
```

### getTos

[](#gettos)

Sometimes you might find yourself wanting to list the currently set Tos. You can do that with `getTos`.

```
$mail   = new SendGrid\Email();
$mail->addTo('foo@bar.com');
$mail->getTos();
```

### removeTo

[](#removeto)

You might also find yourself wanting to remove a single TO from your set list of TOs. You can do that with `removeTo`. You can pass a string or regex to the removeTo method.

```
$mail   = new SendGrid\Email();
$mail->addTo('foo@bar.com');
$mail->removeTo('foo@bar.com');
```

### setFrom

[](#setfrom)

```
$mail   = new SendGrid\Email();
$mail->setFrom('foo@bar.com');
$sendgrid->web->send($mail);
```

### setFromName

[](#setfromname)

```
$mail   = new SendGrid\Email();
$mail->setFrom('foo@bar.com');
$mail->setFromName('Foo Bar');
$mail->setFrom('other@example.com');
$mail->setFromName('Other Guy');
$sendgrid->web->send($mail);
```

### setReplyTo

[](#setreplyto)

```
$mail   = new SendGrid\Email();
$mail->setReplyTo('foo@bar.com');
$sendgrid->web->send($mail);
```

### addCc

[](#addcc)

```
$mail   = new SendGrid\Email();
$mail->addCc('foo@bar.com');
$sendgrid->web->send($mail);
```

### Bcc

[](#bcc)

Use multiple `addTo`s as a superior alternative to `setBcc`.

```
$mail = new SendGrid\Email();
$mail->addTo('foo@bar.com')->
       addTo('someotheraddress@bar.com')->
       addTo('another@another.com')->
       ...
```

But if you do still have a need for Bcc you can do the following.

```
$mail   = new SendGrid\Email();
$mail->addBcc('foo@bar.com');
$sendgrid->web->send($mail);
```

### setSubject

[](#setsubject)

```
$mail   = new SendGrid\Email();
$mail->setSubject('This is a subject');
$sendgrid->web->send($mail);
```

### setText

[](#settext)

```
$mail   = new SendGrid\Email();
$mail->setText('This is some text');
$sendgrid->web->send($mail);
```

### setHtml

[](#sethtml)

```
$mail   = new SendGrid\Email();
$mail->setHtml('This is an html email');
$sendgrid->web->send($mail);
```

### Port and Hostname

[](#port-and-hostname)

For the smtp API you can optionally choose to set the Port and the Hostname.

```
$sendgrid->smtp->setPort('1234567');
$sendgrid->smtp->setHostname('smtp.dude.com');
```

This is useful if you are using a local relay, as documented in [here](http://sendgrid.com/docs/Integrate/#--Power-Users-and-High-Volume-Senders).

### Categories

[](#categories)

Categories are used to group email statistics provided by SendGrid.

To use a category, simply set the category name. Note: there is a maximum of 10 categories per email.

```
$mail = new SendGrid\Email();
$mail->addTo('foo@bar.com')->
       ...
       addCategory("Category 1")->
       addCategory("Category 2");
```

### Attachments

[](#attachments)

Attachments are currently file based only, with future plans for an in memory implementation as well.

File attachments are limited to 7 MB per file.

```
$mail = new SendGrid\Email();
$mail->addTo('foo@bar.com')->
       ...
       addAttachment("../path/to/file.txt");
```

**Important Gotcha**: `setBcc` is not supported with attachments. This is by design. Instead use multiple `addTo`s. Each user will receive their own personalized email with that setup, and only see their own email.

Standard `setBcc` will hide who the email is addressed to. If you use the multiple addTo, each user will receive a personalized email showing \**only* their email. This is more friendly and more personal. Additionally, it is a good idea to use multiple `addTo`s because setBcc is not supported with attachments. This is by design.

So just remember, when thinking 'bcc', instead use multiple `addTo`s.

### From-Name and Reply-To

[](#from-name-and-reply-to)

There are two handy helper methods for setting the From-Name and Reply-To for a message

```
$mail = new SendGrid\Email();
$mail->addTo('foo@bar.com')->
       setReplyTo('someone.else@example.com')->
       setFromName('John Doe')->
       ...
```

### Substitutions

[](#substitutions)

Substitutions can be used to customize multi-recipient emails, and tailor them for the user

```
$mail = new SendGrid\Email();
$mail->addTo('john@somewhere.com')->
       addTo("harry@somewhere.com")->
       addTo("Bob@somewhere.com")->
       ...
       setHtml("Hey %name%, we've seen that you've been gone for a while")->
       addSubstitution("%name%", array("John", "Harry", "Bob"));
```

### Sections

[](#sections)

Sections can be used to further customize messages for the end users. A section is only useful in conjunction with a substition value.

```
$mail = new SendGrid\Email();
$mail->addTo('john@somewhere.com')->
       addTo("harry@somewhere.com")->
       addTo("Bob@somewhere.com")->
       ...
       setHtml("Hey %name%, you work at %place%")->
       addSubstitution("%name%", array("John", "Harry", "Bob"))->
       addSubstitution("%place%", array("%office%", "%office%", "%home%"))->
       addSection("%office%", "an office")->
       addSection("%home%", "your house");
```

### Unique Arguments

[](#unique-arguments)

Unique Arguments are used for tracking purposes

```
$mail = new SendGrid\Email();
$mail->addTo('foo@bar.com')->
       ...
       addUniqueArgument("Customer", "Someone")->
       addUniqueArgument("location", "Somewhere");
```

### Filter Settings

[](#filter-settings)

Filter Settings are used to enable and disable apps, and to pass parameters to those apps.

```
$mail = new SendGrid\Email();
$mail->addTo('foo@bar.com')->
       ...
       addFilterSetting("gravatar", "enable", 1)->
       addFilterSetting("footer", "enable", 1)->
       addFilterSetting("footer", "text/plain", "Here is a plain text footer")->
       addFilterSetting("footer", "text/html", "Here is an HTML footer");
```

### Smtp API Headers

[](#smtp-api-headers)

Smtp API Headers can be used to add existing sendgrid functionality (such as for categories or filters), or custom headers can be added as necessary.

```
$mail = new SendGrid\Email();
$mail->addTo('foo@bar.com')->
       ...
       addSmtpapiHeader("category", "My New Category");
```

### Message Headers

[](#message-headers)

You can add standard email message headers as necessary.

```
$mail = new SendGrid\Email();
$mail->addTo('foo@bar.com')->
       ...
       addMessageHeader('X-Sent-Using', 'SendGrid-API')->
       addMessageHeader('X-Transport', 'web');
```

### Sending to 1,000s of emails in one batch

[](#sending-to-1000s-of-emails-in-one-batch)

Sometimes you might want to send 1,000s of emails in one request. You can do that. It is recommended you break each batch up in 1,000 increements. So if you need to send to 5,000 emails, then you'd break this into a loop of 1,000 emails at a time.

```
$sendgrid   = new SendGrid(SENDGRID_USERNAME, SENDGRID_PASSWORD);
$mail       = new SendGrid\Email();

$recipients = array("alpha@mailinator.com", "beta@mailinator.com", "zeta@mailinator.com");
$names      = array("Alpha", "Beta", "Zeta");

$email->setFrom("from@mailinator.com")->
        setSubject('[sendgrid-php-batch-email]')->
        setTos($recipients)->
        addSubstitution("%name%", $names)->
        setText("Hey %name, we have an email for you")->
        setHtml("Hey %name%, we have an email for you");

$result = $sendgrid->smtp->send($email);
```

### Ignoring SSL certificate verification

[](#ignoring-ssl-certificate-verification)

You can optionally ignore verification of SSL certificate when using the Web API.

```
var options = array("turn_off_ssl_verification" => true);
$sendgrid   = new SendGrid(SENDGRID_USERNAME, SENDGRID_PASSWORD, options);

$email      = new SendGrid\Email();
...
$result     = $sendgrid->web->send($email);
```

Contributing
------------

[](#contributing)

1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Added some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request

Running Tests
-------------

[](#running-tests)

The existing tests in the `test` directory can be run using [PHPUnit](https://github.com/sebastianbergmann/phpunit/) with the following command:

```
composer update --dev
cd test
../vendor/bin/phpunit
```

or if you already have PHPUnit installed globally.

```bash
cd test
phpunit
```

## Known Issues

* When using the smtp version (which is built on top of swiftmailer), any FROM names with parentheses will have the content of the parentheses stripped out. If this happens please use the web version of the library. Read more about this in [issue #27](https://github.com/sendgrid/sendgrid-php/issues/27).
```

###  Health Score

23

—

LowBetter than 26% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 62.5% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/34fe480a7538132395e159b54174806e488eae487d24612c399a1c55e4275312?d=identicon)[tony13tv](/maintainers/tony13tv)

---

Top Contributors

[![shashitechno](https://avatars.githubusercontent.com/u/697420?v=4)](https://github.com/shashitechno "shashitechno (5 commits)")[![tony13tv](https://avatars.githubusercontent.com/u/4117485?v=4)](https://github.com/tony13tv "tony13tv (3 commits)")

### Embed Badge

![Health badge](/badges/tony13tv-silverstripe-sendgrid/health.svg)

```
[![Health](https://phpackages.com/badges/tony13tv-silverstripe-sendgrid/health.svg)](https://phpackages.com/packages/tony13tv-silverstripe-sendgrid)
```

###  Alternatives

[mattketmo/email-checker

Throwaway email detection library

2752.1M5](/packages/mattketmo-email-checker)[sarfraznawaz2005/noty

Laravel package to incorporate noty flash notifications into laravel.

324.5k](/packages/sarfraznawaz2005-noty)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
