PHPackages                             sprintcube/cakephp-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. sprintcube/cakephp-sendgrid

ActiveCakephp-plugin[Mail &amp; Notifications](/categories/mail)

sprintcube/cakephp-sendgrid
===========================

SendGrid plugin for CakePHP 4 - Send emails using SendGrid API

5.0.0(1y ago)551.3k↓29.7%7[2 PRs](https://github.com/sprintcube/cakephp-sendgrid/pulls)MITPHPPHP &gt;=8.1CI failing

Since Sep 26Pushed 1y ago2 watchersCompare

[ Source](https://github.com/sprintcube/cakephp-sendgrid)[ Packagist](https://packagist.org/packages/sprintcube/cakephp-sendgrid)[ RSS](/packages/sprintcube-cakephp-sendgrid/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (4)Dependencies (5)Versions (7)Used By (0)

SendGrid Plugin for CakePHP
===========================

[](#sendgrid-plugin-for-cakephp)

[![CI](https://github.com/sprintcube/cakephp-sendgrid/workflows/CI/badge.svg?branch=master)](https://github.com/sprintcube/cakephp-sendgrid/actions)[![codecov](https://camo.githubusercontent.com/f8b4bedba34b581581b20972e5d2d4c974311fca6294bab24a3a1a2c02f33421/68747470733a2f2f636f6465636f762e696f2f67682f737072696e74637562652f63616b657068702d73656e64677269642f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/sprintcube/cakephp-sendgrid)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE)[![Latest Stable Version](https://camo.githubusercontent.com/73bfd83922e6b6dfeac96bab91945cdf538af0859b1dd5fcb0ef3c63ffed5aff/68747470733a2f2f706f7365722e707567782e6f72672f737072696e74637562652f63616b657068702d73656e64677269642f762f737461626c65)](https://packagist.org/packages/sprintcube/cakephp-sendgrid)[![Total Downloads](https://camo.githubusercontent.com/ca2e45774d0ec8c2a032a654bc5b42c617f2d5e6b1192d410dcefab8c8351630/68747470733a2f2f706f7365722e707567782e6f72672f737072696e74637562652f63616b657068702d73656e64677269642f646f776e6c6f616473)](https://packagist.org/packages/sprintcube/cakephp-sendgrid)

This plugin provides email delivery using [SendGrid](https://sendgrid.com/).

This branch is for use with **CakePHP 5.0+**. For other versions of CakePHP, please use the following version map.

SendGrid PluginBranchCakePHP Core1.x **\[EOL\]**[cake-3.x](https://github.com/sprintcube/cakephp-sendgrid/tree/cake-3.x)3.4+4.x[cake-4.x](https://github.com/sprintcube/cakephp-sendgrid/tree/cake-4.x)4.0+5.x (in progress)[master](https://github.com/sprintcube/cakephp-sendgrid/tree/master)5.0+Requirements
------------

[](#requirements)

This plugin has the following requirements:

- CakePHP 5.0 or greater.
- PHP 8.1 or greater.

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

[](#installation)

You can install this plugin into your CakePHP application using [composer](http://getcomposer.org).

```
composer require sprintcube/cakephp-sendgrid

```

After installation, [Load the plugin](http://book.cakephp.org/3.0/en/plugins.html#loading-a-plugin)

```
Plugin::load('SendGrid');
```

Or, you can load the plugin using the shell command

```
$ bin/cake plugin load SendGrid
```

Setup
-----

[](#setup)

Set your SendGrid Api key in `EmailTransport` settings in app.php

```
'EmailTransport' => [
...
  'sendgrid' => [
      'className' => 'SendGrid.SendGrid',
      'apiKey' => 'your-api-key' // your api key
  ]
]
```

And create new delivery profile in `Email` settings.

```
'Email' => [
    'default' => [
        'transport' => 'default',
        'from' => 'you@localhost',
        //'charset' => 'utf-8',
        //'headerCharset' => 'utf-8',
    ],
    'sendgrid' => [
        'transport' => 'sendgrid'
    ]
]
```

Usage
-----

[](#usage)

You can now simply use the CakePHP `Email` to send an email via SendGrid.

```
$email = new SendGridMailer();
$email->setFrom(['you@yourdomain.com' => 'CakePHP SendGrid'])
    ->setTo('foo@example.com.com')
    ->addTo('bar@example.com')
    ->addCc('john@example.com')
    ->setSubject('Email from CakePHP SendGrid plugin')
    ->deliver('Message from CakePHP SendGrid plugin');
```

That is it.

Advance Use
-----------

[](#advance-use)

You can also use few more options to send email via SendGrid APIs. To do so, just call the appropriate methods before sending the email.

### Custom Headers

[](#custom-headers)

You can pass your own headers. It must be prefixed with "X-". Use the default `Email::setHeaders` method like,

```
$email = new SendGridMailer();
$email->setFrom(['you@yourdomain.com' => 'CakePHP SendGrid'])
    ->setTo('foo@example.com.com')
    ->setHeaders([
        'X-Custom' => 'headervalue',
        'X-MyHeader' => 'myvalue'
    ])
    ->setSubject('Email from CakePHP SendGrid plugin')
    ->deliver('Message from CakePHP SendGrid plugin');
```

> When sending request, `X-` will be removed from header name e.g. X-MyHeader will become MyHeader

### Attachments

[](#attachments)

Set your attachments using `Email::setAttachments` method.

```
$email = new SendGridMailer();
$email->setFrom(['you@yourdomain.com' => 'CakePHP SendGrid'])
    ->setTo('foo@example.com.com')
    ->setSubject('Email from CakePHP SendGrid plugin')
    ->setAttachments([
        'cake_icon1.png' => Configure::read('App.imageBaseUrl') . 'cake.icon.png',
        'cake_icon2.png' => ['file' => Configure::read('App.imageBaseUrl') . 'cake.icon.png'],
        WWW_ROOT . 'favicon.ico'
    ])
    ->deliver('Message from CakePHP SendGrid plugin');
```

> To send inline attachment, use `contentId` parameter while setting attachment.

### Template

[](#template)

You can use the template created in SendGrid backend. Get the template id by either using their API or from the URL. Set the template id using `setTemplate` method.

```
$email = new SendGridMailer();
$email->setTo('foo@example.com.com')
    ->setTemplate('d-xxxxxx')
    ->deliver();
```

### Schedule

[](#schedule)

You can schedule the email to be sent in future date. You can set upto 72 hours in future as per SendGrid documentation. You need to pass a unix timestamp value.

```
$email = new SendGridMailer();
$email->setTo('foo@example.com.com')
    ->setSendAt(1649500630)
    ->deliver();
```

Webhooks
--------

[](#webhooks)

You can receive status events from SendGrid. This allows you ensure that SendGrid was able to send the email recording bounces etc.

### Webhook Config

[](#webhook-config)

You will require a Table in the database to record the emails sent. You can use the lorenzo/cakephp-email-queue plugin to queue the emails and in that case you would use the email\_queue table. However you can create your own table/Model as long as it has at least three columns. They can be called anything but they must have the correct types.

When you send the email the deliver function will return an array with a 'messageId' element if it successfully connected to SendGrid. This needs to be recorded in the status\_id field.

- status\_id VARCHAR(100)
- status VARCHAR(100)
- status\_message TEXT

You need to map this table and these fields in you app\_local.php config

```
    'sendgridWebhook' => [
        'tableClass' => 'EmailQueue', // The table name that stores email data
        'uniqueIdField' => 'status_id', // The field name that stores the unique message ID VARCHAR(100)
        'statusField' => 'status', // The field name that stores the status of the email status VARCHAR(100)
        'statusMessageField' => 'status_message', // The field name that stores the status messages TEXT
        'debug' => 'true', // write incoming requests to debug log
        'secure' => 'true', // enable SendGrid signed webhook security. You should enable this in production
        'verification_key' => '', // The verification key from SendGrid
    ],
```

You will need to login to your SendGrid Account and configure your domain and the events that you want to track

[https://app.sendgrid.com/settings/mail\_settings/webhook\_settings](https://app.sendgrid.com/settings/mail_settings/webhook_settings)

The return url needs to be set to

-

The CSRF protection middleware needs to allow posts to the webhooks controller in Application.php Remove the current CSRF protection middleware and replace it with the following. If you already have CSRF exceptions then add the Webhooks one

```
  $csrf = new CsrfProtectionMiddleware();

  $csrf->skipCheckCallback(function ($request) {
         // Skip token check for API URLs.
        if ($request->getParam('controller') === 'Webhooks') {
           return true;
          }
  });

    // Ensure routing middleware is added to the queue before CSRF protection middleware.
  $middlewareQueue->add($csrf);

  return $middlewareQueue;
```

If the authentication plugin () is used for authentication the webhook action should work OK. If you have a different authentication method then you will need to add an exception for the webhook action. /send-grid/webhooks/index

#### Webhook Signature Verification

[](#webhook-signature-verification)

SendGrid allows you to sign the webhook requests. This is a good idea in production to keep the webhook secure. You will need to enable this in your SendGrid account and then set secure to true and add your verification key to your app\_local.php config file.

. Enable signed event webhook and follow the instructions to get the verification key.

Reporting Issues
----------------

[](#reporting-issues)

If you have a problem with this plugin or any bug, please open an issue on [GitHub](https://github.com/sprintcube/cakephp-sendgrid/issues).

###  Health Score

46

—

FairBetter than 93% of packages

Maintenance41

Moderate activity, may be stable

Popularity36

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity75

Established project with proven stability

 Bus Factor1

Top contributor holds 73.8% 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.

###  Release Activity

Cadence

Every ~765 days

Total

4

Last Release

493d ago

Major Versions

v1.0.0 → v4.0.02022-04-09

4.0.1 → 5.0.02025-01-10

PHP version history (2 changes)v4.0.0PHP &gt;=7.2

5.0.0PHP &gt;=8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/b9a095d4cabe4d7cf8745d51242e1c70d06cb18437001c82c68c5d778cd94fbb?d=identicon)[sprintcube](/maintainers/sprintcube)

---

Top Contributors

[![narendravaghela](https://avatars.githubusercontent.com/u/1432986?v=4)](https://github.com/narendravaghela "narendravaghela (48 commits)")[![jubbs](https://avatars.githubusercontent.com/u/7624010?v=4)](https://github.com/jubbs "jubbs (14 commits)")[![stickler-ci](https://avatars.githubusercontent.com/u/16011037?v=4)](https://github.com/stickler-ci "stickler-ci (3 commits)")

---

Tags

cakephpcakephp-plugincakephp3cakephp4emailphpsendgridemailcakephpsendgrid

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/sprintcube-cakephp-sendgrid/health.svg)

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

###  Alternatives

[sendgrid/sendgrid

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

1.5k47.5M164](/packages/sendgrid-sendgrid)[sendgrid/smtpapi

Build SendGrid X-SMTPAPI headers in PHP.

696.5M2](/packages/sendgrid-smtpapi)[slm/mail

Integration of various email service providers in the Laminas\\Mail

108732.4k1](/packages/slm-mail)[omnimail/omnimail

PHP Library to send email across all platforms using one interface.

32934.3k](/packages/omnimail-omnimail)[lorenzo/cakephp-email-queue

Queue, preview and and send emails stored in the database

57121.5k1](/packages/lorenzo-cakephp-email-queue)[fastglass/sendgrid

This library allows you to send emails through SendGrid using PHP and Guzzle 6.x.

213.7M](/packages/fastglass-sendgrid)

PHPackages © 2026

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