Created
March 8, 2018 15:02
-
-
Save savepong/9f2696549e25135906e5caa21773e3b0 to your computer and use it in GitHub Desktop.
Laravel 5.6 SendGrid Integate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# installed with composer | |
composer require s-ichikawa/laravel-sendgrid-driver | |
# Add the sendgrid service provider in config/app.php: | |
'providers' => [ | |
Sichikawa\LaravelSendgridDriver\SendgridTransportServiceProvider::class | |
]; | |
# Config on .env | |
MAIL_DRIVER=sendgrid | |
SENDGRID_API_KEY='YOUR_SENDGRID_API_KEY' | |
# config/services.php (In using lumen, require creating config directory and file.) | |
'sendgrid' => [ | |
'api_key' => env('SENDGRID_API_KEY'), | |
], | |
# Use in Mailable | |
<? | |
use Sichikawa\LaravelSendgridDriver\SendGrid; | |
class SendGridSample extends Mailable | |
{ | |
use SendGrid; | |
public function build() | |
{ | |
return $this | |
->view('template name') | |
->subject('subject') | |
->from('from@example.com') | |
->to(['to@example.com']) | |
->sendgrid([ | |
'personalizations' => [ | |
[ | |
'substitutions' => [ | |
':myname' => 's-ichikawa', | |
], | |
], | |
], | |
]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment