venturo / laravel-sendgrid
send email with laravel and sendgrid
1.0.1
2023-10-31 08:28 UTC
Requires
- sendgrid/sendgrid: ^8.0
README
Package Laravel SendGrid (asynchronous) with Redis
How to install Venturo Laravel SendGrid
- This library can be found on Packagist
- for an easier management of projects dependencies using Composer.
- Compressed archives of each release are available on GitLab.
composer require venturo/laravel-sendgrid
How to use Venturo Laravel SendGrid
First, you need to setting your .env file
Queue Connection
QUEUE_CONNECTION=redis
Redis
REDIS_CLIENT=predis REDIS_HOST=redis-10324.c252**** REDIS_PASSWORD=Db5E7plgFA**** REDIS_PORT=10324
- SendGrid
SENDGRID_API_KEY=SG.5bntrsM4QyCwN**** SENDGRID_QUEUE=sendgrid
Now you can use this packages
Example of Venturo Laravel SendGrid
use Venturo\LaravelSendGrid\SendGrid;
Send Notification
$sendGrid = new SendGrid();
$data = [
'from' => [
'email' => '****',
'name' => '****',
],
'to' => [
'email' => '****@****.com',
'name' => '**** ****',
],
'subject' => '****',
'body' => '****',
];
$send = $sendGrid->send($data);
// {
// status: 1,
// id: "ySy2WlhqTbccLoeU4faQxuWHS6TO3095"
// }
// you can use id to check notification status (pending / finished)
$data can be filled with
- Template ID from sendgrid
$data = [ 'from' => [ 'email' => '****', 'name' => '****', ], 'to' => [ 'email' => '****@****.com', 'name' => '**** ****', ], 'subject' => '****' // fill with template id you got from sendgrid 'templateId' => 'd-13b8f94fbcae4****' ];
$send = $sendGrid->sendWithTemplate($data);
- Multiple Recipient
$data = [
'from' => [
'email' => '****',
'name' => '****',
],
// fill with array
'to' => [
[
'email' => '****@****.com',
'name' => '**** ****',
],
[
'email' => '****@****.com',
'name' => '**** ****',
],
],
'subject' => '****',
'body' => '****',
];
**If you want to check email status (pending / finished), you can use**
$sendgrid = new SendGrid();
// $id = id you got from send email function $inQueue = $sendgrid->search($id); // return if status 0 = finished, 1 = pending // { // status: 0 // }
**Oh, dont forget to run this command to make queue laravel work**
php artisan queue:work
**If queue success but email not sent, you can check failed_sendgrid table in your primary database (eg : mysql)**