PHPackages                             nyx-solutions/yii2-nyx-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. nyx-solutions/yii2-nyx-sendgrid

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

nyx-solutions/yii2-nyx-sendgrid
===============================

Yii2 Mailer extension for SendGrid with batch mailing support.

2.0.1(3y ago)094MITPHPPHP &gt;=8.1.0 &lt;8.2

Since Jun 2Pushed 3y ago1 watchersCompare

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

READMEChangelog (2)Dependencies (2)Versions (3)Used By (0)

Yii2 NYX SendGrid
-----------------

[](#yii2-nyx-sendgrid)

Yii2 Mailer extension for SendGrid with batch mailing support.

[![Latest Stable Version](https://camo.githubusercontent.com/fa583c0e1781a4e44c90df264386706d3ef017e818db8b53f26196c8094afd61/68747470733a2f2f706f7365722e707567782e6f72672f6e79782d736f6c7574696f6e732f796969322d6e79782d73656e64677269642f762f737461626c65)](https://packagist.org/packages/nyx-solutions/yii2-nyx-sendgrid)[![Total Downloads](https://camo.githubusercontent.com/f119b42a059f63851fcb91122778d5e12686407648b7098e2269043eac8f1bf6/68747470733a2f2f706f7365722e707567782e6f72672f6e79782d736f6c7574696f6e732f796969322d6e79782d73656e64677269642f646f776e6c6f616473)](https://packagist.org/packages/nyx-solutions/yii2-nyx-sendgrid)[![Latest Unstable Version](https://camo.githubusercontent.com/dc3f430aa727e53b738186d86d5e0bb3cebf6a11e3a7c2771afe8ad67a789e0b/68747470733a2f2f706f7365722e707567782e6f72672f6e79782d736f6c7574696f6e732f796969322d6e79782d73656e64677269642f762f756e737461626c65)](https://packagist.org/packages/nyx-solutions/yii2-nyx-sendgrid)[![License](https://camo.githubusercontent.com/a14fef46c732454e0f47cc6bf222b824256bef56bda5ba97e1da058a30b22f7a/68747470733a2f2f706f7365722e707567782e6f72672f6e79782d736f6c7574696f6e732f796969322d6e79782d73656e64677269642f6c6963656e7365)](https://packagist.org/packages/nyx-solutions/yii2-nyx-sendgrid)[![Monthly Downloads](https://camo.githubusercontent.com/a6e02d124975d57e6955dca5ef34f1caa72124614a65d82ccc15c97d26f0b707/68747470733a2f2f706f7365722e707567782e6f72672f6e79782d736f6c7574696f6e732f796969322d6e79782d73656e64677269642f642f6d6f6e74686c79)](https://packagist.org/packages/nyx-solutions/yii2-nyx-sendgrid)[![Daily Downloads](https://camo.githubusercontent.com/137983adbb367f6b10e1b9ebfbda9974722a71cb83d0386833f6d5553775f0c4/68747470733a2f2f706f7365722e707567782e6f72672f6e79782d736f6c7574696f6e732f796969322d6e79782d73656e64677269642f642f6461696c79)](https://packagist.org/packages/nyx-solutions/yii2-nyx-sendgrid)[![composer.lock](https://camo.githubusercontent.com/b6ca57bf11a56dda33991a776d2618c0ceb4a6d64a83d00296acac294f553b2f/68747470733a2f2f706f7365722e707567782e6f72672f6e79782d736f6c7574696f6e732f796969322d6e79782d73656e64677269642f636f6d706f7365726c6f636b)](https://packagist.org/packages/nyx-solutions/yii2-nyx-sendgrid)

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

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

```
php composer.phar require --prefer-dist nyx-solutions/yii2-nyx-sendgrid

```

or add

```
"nyx-solutions/yii2-nyx-sendgrid": "~2.0.0"
```

to the require section of your application's `composer.json` file.

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

```
'mailer' => [
    'class' => \nyx\mail\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)

### 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])      // or just $user->email
    ->setFrom(['alerts@example.com' => 'Alerts'])
    ->setReplyTo('noreply@example.com')
    ->setSubject('Hey -username-, Read This Email')
    ->setHtmlBody('Dear -username-,My HTML message here')
    ->setTextBody('Dear -username-,\n\nMy Text message here')
    //->setTemplateId('1234')
    //->addSection('%section1%', 'This is my section1')
    //->addHeader('X-Track-UserType', 'admin')
    //->addHeader('X-Track-UID', Yii::$app->user->id)
    //->addCategory('tests')
    //->addCustomArg('test_arg', 'my custom arg')
    //->setSendAt(time() + (5 * 60))
    //->setBatchId(Yii::$app->mailer->createBatchId())
    //->setIpPoolName('7')
    //->attach(Yii::getAlias('@webroot/files/attachment.pdf'))
    ->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;
//$batchId = Yii::$app->mailer->createBatchId();
//$sendTime = time() + (5 * 60);      // 5 minutes from now

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-, Read This Email')
        ->setHtmlBody('Dear -username-,My HTML message here')
        ->setTextBody('Dear -username-,\n\nMy Text message here');
        //->setTemplateId('1234')
        //->addSection('%section1%', 'This is my section1')
        //->addHeader('X-Track-UserType', 'admin')
        //->addHeader('X-Track-UID', Yii::$app->user->id)
        //->addCategory('tests')
        //->addCustomArg('test_arg', 'my custom arg')
        //->setSendAt($sendTime)
        //->setBatchId($batchId)
        //->setIpPoolName('7')
        //->attach(Yii::getAlias('@webroot/files/attachment.pdf'));

    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.

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity61

Established project with proven stability

 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 ~0 days

Total

2

Last Release

1440d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/f7c641a4199171cc30bf08b9bf67636a8463acf86813fa259aab131b5bd5a161?d=identicon)[nyx-solutions](/maintainers/nyx-solutions)

---

Top Contributors

[![jsas4coding](https://avatars.githubusercontent.com/u/4156892?v=4)](https://github.com/jsas4coding "jsas4coding (3 commits)")

---

Tags

sendgridyii2yii2 maileryii2 sendgridyii2 sendgrid mailer

### Embed Badge

![Health badge](/badges/nyx-solutions-yii2-nyx-sendgrid/health.svg)

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

###  Alternatives

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