PHPackages                             priyolahiri/sendgrid-php - 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. priyolahiri/sendgrid-php

ActiveLibrary[Mail &amp; Notifications](/categories/mail)

priyolahiri/sendgrid-php
========================

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

1.0.0(13y ago)02591MITPHP

Since Apr 2Pushed 13y ago1 watchersCompare

[ Source](https://github.com/priyolahiri/sendgrid-php)[ Packagist](https://packagist.org/packages/priyolahiri/sendgrid-php)[ Docs](http://sendgrid.com)[ RSS](/packages/priyolahiri-sendgrid-php/feed)WikiDiscussions master Synced 4w ago

READMEChangelogDependenciesVersions (5)Used By (0)

sendgrid-php
============

[](#sendgrid-php)

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

License
-------

[](#license)

Licensed under the MIT License.

Downloading
-----------

[](#downloading)

Installing the SendGrid package is as simple as adding it to your project's include path and requiring it. If you're using git, you can just clone down the repo like this:

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

```

**Note**: If you don't have git or would rather install by unpacking a Zip or Tarball, you can always grab the latest version of the package from [the downloads page](https://github.com/sendgrid/sendgrid-php/downloads).

Testing
-------

[](#testing)

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

```
phpunit Test/
```

## 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
  1. Creating a SendGrid Mail object, and setting its data
  1. Sending the mail using either SMTP API or Web API.

## Mail Usage ##

To begin using this library, you must first include it

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

Then, initialize the SendGrid object with your SendGrid credentials

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

Create a new SendGrid Mail object and add your message details

```php
$mail = new SendGrid\Mail();
$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 (SMTP or Web)

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

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

### Using 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.

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

### Using 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.

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

### Using Substitutions ###

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

```php
$mail = new SendGrid\Mail();
$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"));
```

### Using Sections ###

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

```php
$mail = new SendGrid\Mail();
$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");
```

### Using Unique Arguments ###

Unique Arguments are used for tracking purposes

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

### Using Filter Settings ###

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

```php
$mail = new SendGrid\Mail();
$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");
```

### Using Headers ###

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

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

```

###  Health Score

30

—

LowBetter than 62% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

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.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

4835d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1254077?v=4)[Priyadarshi Lahiri](/maintainers/priyolahiri)[@priyolahiri](https://github.com/priyolahiri)

---

Top Contributors

[![theycallmeswift](https://avatars.githubusercontent.com/u/434373?v=4)](https://github.com/theycallmeswift "theycallmeswift (7 commits)")[![cjbuchmann](https://avatars.githubusercontent.com/u/526429?v=4)](https://github.com/cjbuchmann "cjbuchmann (5 commits)")[![priyolahiri](https://avatars.githubusercontent.com/u/1254077?v=4)](https://github.com/priyolahiri "priyolahiri (2 commits)")[![hellogerard](https://avatars.githubusercontent.com/u/200488?v=4)](https://github.com/hellogerard "hellogerard (1 commits)")

### Embed Badge

![Health badge](/badges/priyolahiri-sendgrid-php/health.svg)

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

###  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)
