s-ichikawa/laravel-sendgrid-driver
概要
This library can add sendgrid driver into the laravel's mail configure.
Web・アプリ開発計測したスター増加
- 24時間
- 0
- 7日間
- 0
- 15日間
- 0
- 1か月
- 履歴を収集中
期間ごとの純増数です。期間は重複しており、日別の値ではありません。未計測の値は空欄です。スター数は注目度の指標であり、品質の保証ではありません。
README.md
オリジナルLaravel SendGrid Driver
A Mail Driver with support for Sendgrid Web API, using the original Laravel API. This library extends the original Laravel classes, so it uses exactly the same methods.
To use this package required your Sendgrid Api Key. Please make it Here.
Compatibility
| Laravel | laravel-sendgrid-driver |
|---|---|
| 9, 10, 11, 12, 13 | ^4.0 |
| 7, 8 | ^3.0 |
| 5, 6 | ^2.0 |
Install (for Laravel)
Add the package to your composer.json and run composer update.
"require": {
"s-ichikawa/laravel-sendgrid-driver": "^4.0"
},
or installed with composer
$ composer require s-ichikawa/laravel-sendgrid-driver
Install (for Lumen)
Add the package to your composer.json and run composer update.
"require": {
"s-ichikawa/laravel-sendgrid-driver": "^4.0"
},
or installed with composer
$ composer require "s-ichikawa/laravel-sendgrid-driver"
Add the sendgrid service provider in bootstrap/app.php
$app->configure('mail');
$app->configure('services');
$app->register(Sichikawa\LaravelSendgridDriver\MailServiceProvider::class);
unset($app->availableBindings['mailer']);
Create mail config files. config/mail.php
<?php
return [
'driver' => env('MAIL_DRIVER', 'sendgrid'),
];
Configure
.env
MAIL_DRIVER=sendgrid
SENDGRID_API_KEY='YOUR_SENDGRID_API_KEY'
# Optional: for 7+ laravel projects
MAIL_MAILER=sendgrid
config/services.php (In using lumen, require creating config directory and file.)
'sendgrid' => [
'api_key' => env('SENDGRID_API_KEY'),
],
config/mail.php
'mailers' => [
'sendgrid' => [
'transport' => 'sendgrid',
],
],
endpoint config
If you need to set custom endpoint, you can set any endpoint by using endpoint key.
For example, calls to SendGrid API through a proxy, call endpoint for confirming a request.
'sendgrid' => [
'api_key' => env('SENDGRID_API_KEY'),
'endpoint' => 'https://custom.example.com/send',
],
How to use
Every request made to /v3/mail/send will require a request body formatted in JSON containing your email’s content and metadata. Required parameters are set by Laravel's usually mail sending, but you can also use useful features like "categories" and "send_at".
more info https://www.twilio.com/docs/sendgrid/api-reference/mail-send/mail-send
Laravel 10, 11:
<?
use Sichikawa\LaravelSendgridDriver\SendGrid;
class SendGridSample extends Mailable
{
use SendGrid;
public function envelope(): Envelope
{
$this->sendgrid([
'personalizations' => [
[
'to' => [
['email' => '[email protected]', 'name' => 'to1'],
['email' => '[email protected]', 'name' => 'to2'],
],
'cc' => [
['email' => '[email protected]', 'name' => 'cc1'],
['email' => '[email protected]', 'name' => 'cc2'],
],
'bcc' => [
['email' => '[email protected]', 'name' => 'bcc1'],
['email' => '[email protected]', 'name' => 'bcc2'],
],
],
],
'categories' => ['user_group1'],
]);
return new Envelope(
from: '[email protected]',
replyTo: '[email protected]',
subject: 'example',
);
}
}
Laravel 9:
<?
use Sichikawa\LaravelSendgridDriver\SendGrid;
class SendGridSample extends Mailable
{
use SendGrid;
public function build():
{
return $this
->view('template name')
->subject('subject')
->from('[email protected]')
->to(['[email protected]'])
->sendgrid([
'personalizations' => [
[
'to' => [
['email' => '[email protected]', 'name' => 'to1'],
['email' => '[email protected]', 'name' => 'to2'],
],
'cc' => [
['email' => '[email protected]', 'name' => 'cc1'],
['email' => '[email protected]', 'name' => 'cc2'],
],
'bcc' => [
['email' => '[email protected]', 'name' => 'bcc1'],
['email' => '[email protected]', 'name' => 'bcc2'],
],
],
],
'categories' => ['user_group1'],
]);
}
}
Using Template Id
Illuminate\Mailer has generally required a view file. But in case of using template id, set an empty array at view function.
Laravel 10, 11:
<?
public function envelope(): Envelope
{
$this->sendgrid([
'personalizations' => [
[
'dynamic_template_data' => [
'title' => 'Subject',
'name' => 's-ichikawa',
],
],
],
'template_id' => config('services.sendgrid.templates.dynamic_template_id'),
]);
return new Envelope(
from: '[email protected]',
replyTo: '[email protected]',
subject: 'example',
);
}
Laravel 9:
<?
public function build():
{
return $this
->view('template name')
->subject('subject')
->from('[email protected]')
->to(['[email protected]'])
->sendgrid([
'personalizations' => [
[
'dynamic_template_data' => [
'title' => 'Subject',
'name' => 's-ichikawa',
],
],
],
'template_id' => config('services.sendgrid.templates.dynamic_template_id'),
]);
}
関連プロジェクトを探す
読み込み中…