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

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

wowmaking/yii2-sendgrid
=======================

Yii2 Sendgrid Mailer extension

011PHP

Since Apr 2Pushed 2y agoCompare

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

READMEChangelogDependenciesVersions (1)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

13

—

LowBetter than 1% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity19

Early-stage or recently created project

 Bus Factor1

Top contributor holds 89.2% 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/b830ebdce0fc49c5d178f7e11e61234e49d15739e0f2a3f5577aa08ecc2a1e4f?d=identicon)[alexyermalovich](/maintainers/alexyermalovich)

---

Top Contributors

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

### Embed Badge

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

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

###  Alternatives

[tijsverkoyen/css-to-inline-styles

CssToInlineStyles is a class that enables you to convert HTML-pages/files into HTML-pages/files with inline styles. This is very useful when you're sending emails.

5.8k505.3M227](/packages/tijsverkoyen-css-to-inline-styles)[minishlink/web-push

Web Push library for PHP

1.9k12.0M53](/packages/minishlink-web-push)[laravel-notification-channels/twilio

Provides Twilio notification channel for Laravel

2587.7M12](/packages/laravel-notification-channels-twilio)[spatie/url-signer

Generate a url with an expiration date and signature to prevent unauthorized access

4422.3M16](/packages/spatie-url-signer)[mattketmo/email-checker

Throwaway email detection library

2742.0M5](/packages/mattketmo-email-checker)[laravel-notification-channels/discord

Laravel notification driver for Discord.

2371.3M11](/packages/laravel-notification-channels-discord)

PHPackages © 2026

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