PHPackages                             marketforce-info/yii2-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. marketforce-info/yii2-sendgrid

ActiveYii2-extension[Mail &amp; Notifications](/categories/mail)

marketforce-info/yii2-sendgrid
==============================

Yii2 Sendgrid Mailer extension

1.0.3(2y ago)014.8k↓22.6%3[1 issues](https://github.com/marketforce-info/yii2-sendgrid/issues)[1 PRs](https://github.com/marketforce-info/yii2-sendgrid/pulls)MITPHPPHP ^7.4 || ^8

Since Oct 18Pushed 2y ago1 watchersCompare

[ Source](https://github.com/marketforce-info/yii2-sendgrid)[ Packagist](https://packagist.org/packages/marketforce-info/yii2-sendgrid)[ Docs](https://github.com/marketforce-info/yii2-sendgrid)[ RSS](/packages/marketforce-info-yii2-sendgrid/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (4)Dependencies (6)Versions (6)Used By (0)

MarketforceInfo/Yii2-SendGrid
=============================

[](#marketforceinfoyii2-sendgrid)

[![Code Checks](https://camo.githubusercontent.com/a64c736c7854c773fb60c6592026ac6a8f701cda76eac25ac4ba82d893fe07d4/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6d61726b6574666f7263652d696e666f2f796969322d73656e64677269642f636f64652d636865636b732e796d6c3f6272616e63683d6d61696e266c6f676f3d676974687562)](https://github.com/marketforce-info/yii2-sendgrid/actions/workflows/code-checks.yml)[![Latest Stable Version](https://camo.githubusercontent.com/cd9be6e54af77586e77bde223e58734619c1ae55e59acf44ee08aa688fd75dd4/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f6d61726b6574666f7263652d696e666f2f796969322d73656e64677269643f6c6f676f3d7061636b6167697374)](https://github.com/marketforce-info/yii2-sendgrid/releases)[![Total Downloads](https://camo.githubusercontent.com/9f59bd95acbc54b6c7024141bf4ccfa7e22062a838eed6884133205e46d08d4b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d61726b6574666f7263652d696e666f2f796969322d73656e64677269643f6c6f676f3d7061636b6167697374)](https://packagist.org/packages/marketforce-info/yii2-sendgrid)[![Licence](https://camo.githubusercontent.com/edeb50a4599ee49a72f7d75a5cced02c2fa38e76981a383384fc6b772459e468/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6d61726b6574666f7263652d696e666f2f796969322d73656e64677269642e737667)](https://camo.githubusercontent.com/edeb50a4599ee49a72f7d75a5cced02c2fa38e76981a383384fc6b772459e468/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6d61726b6574666f7263652d696e666f2f796969322d73656e64677269642e737667)

Description
-----------

[](#description)

Yii2 Mailer extension for SendGrid with batch mailing support.

### Recommended alternative

[](#recommended-alternative)

A possible alternative to this component is the following combination

- [Yii2 Symfony Mailer](https://github.com/yiisoft/yii2-symfonymailer)
- [Symfony Mailer](https://symfony.com/doc/current/mailer.html)
- [SendGrid Bridge](https://github.com/symfony/symfony/blob/6.3/src/Symfony/Component/Mailer/Bridge/Sendgrid/README.md)

---

### Installation

[](#installation)

```
$ composer require marketforce-info/yii2-sendgrid
```

Then configure your `mailer` component in your `main-local.php` (advanced) or `web.php` (basic) like so:

```
    'mailer' => [
        'class' => \MarketforceInfo\SendGrid\Mailer::class,
        'viewPath' => '@common/mail',
        // send all mails to a file by default. You have to set
        // 'useFileTransport' to false and configure a transport
        // for the mailer to send real emails.
        'useFileTransport' => false,
        'apiKey' => '[YOUR_SENDGRID_API_KEY]',
    ],
```

Do not forget to replace `apiKey` with your SendGrid API key. It must have permissions to send emails.

### Usage

[](#usage)

#### Basic

[](#basic)

```
    $mailer = Yii::$app->mailer;
    $message = $mailer->compose()
        ->setTo('user@example.com')
        ->setFrom(['alerts@example.com' => 'Alerts'])
        ->setReplyTo('noreply@example.com')
        ->setSubject('Example Email Subject')
        ->setTextBody('Example email body.')
        ->send();
```

#### Single Mailing

[](#single-mailing)

```
    $user = \common\models\User::find()->select(['id', 'username', 'email'])->where(['id' => 1])->one();

    $mailer = Yii::$app->mailer;
    $message = $mailer->compose()
        ->setTo([$user->email => $user->username])
        ->setFrom(['alerts@example.com' => 'Alerts'])
        ->setReplyTo('noreply@example.com')
        ->setSubject('Example Email Subject')
        ->setHtmlBody('Dear -username-,Example email HTML body.')
        ->setTextBody('Dear -username-,\n\nExample email text body.')
        ->addSubstitution('-username-', $user->username)
        ->send();

    if ($message === true) {
        echo 'Success!';
        echo '' . print_r($mailer->getRawResponses(), true) . '';
    } else {
        echo 'Error!';
        echo '' . print_r($mailer->getErrors(), true) . '';
    }
```

#### Batch Mailing

[](#batch-mailing)

If you want to send to multiple recipients, you need to use the below method to batch send.

```
    $mailer = Yii::$app->mailer;

    foreach (User::find()->select(['id', 'username', 'email'])->batch(500) as $users) {

        $message = $mailer->compose()
            ->setFrom(['alerts@example.com' => 'Alerts'])
            ->setReplyTo('noreply@example.com')
            ->setSubject('Hey -username-, Example Email Subject')
            ->setHtmlBody('Dear -username-,Example email HTML body.')
            ->setTextBody('Dear -username-,\n\nExample email text body.')

        foreach ( $users as $user )
        {
            // A Personalization Object Helper would be nice here...
            $personalization = [
                'to' => [$user->email => $user->username],      // or just `email@example.com`
                //'cc' => 'cc@example.com',
                //'bcc' => 'bcc@example.com',
                //'subject' => 'Hey -username-, Custom message for you!',
                //'headers' => [
                //    'X-Track-RecipId' => $user->id,
                //],
                'substitutions' => [
                    '-username-' => $user->username,
                ],
                //'custom_args' => [
                //    'user_id' => $user->id,
                //    'type' => 'marketing',
                //],
                //'send_at' => $sendTime,
            ];
            $message->addPersonalization($personalization);
        }

        $result = $message->send();
    }

    if ($result === true) {
        echo 'Success!';
        echo '' . print_r($mailer->getRawResponses(), true) . '';
    } else {
        echo 'Error!';
        echo '' . print_r($mailer->getErrors(), true) . '';
    }
```

**NOTE:** SendGrid supports a max of 1,000 recipients. This is a total of the to, bcc, and cc addresses. I recommend using `500` for the batch size. This should be large enough to process thousands of emails efficiently without risking getting errors by accidentally breaking the 1,000 recipients rule. If you are not using any bcc or cc addresses, you *could* raise the batch number a little higher. Theoretically, you should be able to do 1,000 but I would probably max at 950 to leave some wiggle room.

---

### Known Issues

[](#known-issues)

- `addSection()` - There is currently an issue with the SendGrid API where sections are not working.
- `setSendAt()` - There is currently an issue with the SendGrid API where using `send_at` where the time shows the queued time not the actual time that the email was sent.
- `setReplyTo()` - There is currently an issue with the SendGrid PHP API where the ReplyTo address only accepts the email address as a string. So you can't set a name.

---

### Todo

[](#todo)

There are a few things left that I didn't get to:

- ASM
- mail\_settings
- tracking\_settings

Contributions gratefully accepted in the form issues or PRs.

Attribution
-----------

[](#attribution)

This extension was originally created by

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity28

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~96 days

Total

5

Last Release

923d ago

Major Versions

1.0.1 → v2.x-dev2022-12-03

PHP version history (2 changes)1.0.0PHP ^7.4 || ^8

v2.x-devPHP ^8

### Community

Maintainers

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

---

Top Contributors

[![lrichardsmf](https://avatars.githubusercontent.com/u/115080961?v=4)](https://github.com/lrichardsmf "lrichardsmf (33 commits)")

---

Tags

sendgridmaileryii2

###  Code Quality

TestsPHPUnit

Code StyleECS

### Embed Badge

![Health badge](/badges/marketforce-info-yii2-sendgrid/health.svg)

```
[![Health](https://phpackages.com/badges/marketforce-info-yii2-sendgrid/health.svg)](https://phpackages.com/packages/marketforce-info-yii2-sendgrid)
```

###  Alternatives

[nickcv/yii2-mandrill

Mandrill Api Integration for Yii2

29554.2k2](/packages/nickcv-yii2-mandrill)[yarcode/yii2-mailgun-mailer

Mailgun mailer implementation for Yii2

1576.0k](/packages/yarcode-yii2-mailgun-mailer)[bryglen/yii2-sendgrid

Sendgrid Mailer for Yii 2

1353.5k](/packages/bryglen-yii2-sendgrid)

PHPackages © 2026

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