Service para envio de e-mail via queue easy no Laravel
composer require gsferro/servicemail
- Adicione o ServiceProvider em providers de
app.php
/*
|---------------------------------------------------
| ServiceMail
|---------------------------------------------------
*/
\Gsferro\ServiceMail\Providers\ServiceMailServiceProvider::class,
- Adicione em
$listen
o event emEventServiceProvider.php
/*
|---------------------------------------------------
| ServiceMail
|---------------------------------------------------
*/
'Gsferro\ServiceMail\Events\MailerEvent' => [
'Gsferro\ServiceMail\Listeners\MailerJobListener',
],
- Publish config
php artisan vendor:publish --provider="Gsferro\ServiceMail\Providers\ServiceMailServiceProvider" --tag=config
<?php
servicemail()->send(
string $view,
string $subject,
string $to,
$data,
?\DateTime $timeEvent = null,
string $attach = null,
$cc = null
);
- Gerar migration
- php artisan queue:table
- php artisan queue:failed-table
- set a variavel
SERVICEMAIL_REDIRECT
no .env ou dentro do config/servicemail.php para enviar o email para si como debug/teste
- Crie o banco local
touch database/database.sqlite
- Publish Migrations em migrations/servicemail
php artisan vendor:publish --provider="Gsferro\ServiceMail\Providers\ServiceMailServiceProvider" --tag=migrations
- Altere o arquivo
config/database.php
'connections' => [
'sqlite' => [
'driver' => 'sqlite',
'database' => database_path( 'database.sqlite' ),
'prefix' => '',
'foreign_key_constraints' => env( 'DB_FOREIGN_KEYS', true ),
],
- Altere o arquivo
config/queue.php
'connections' => [
'sqlite' => [
'connection' => 'sqlite',
'driver' => 'database',
'table' => 'jobs',
'queue' => 'default',
'retry_after' => 90,
],
- Altere o arquivo
.env
QUEUE_CONNECTION="sqlite"
Ou coloque direto no arquivo config/queue.php
[
'default' => "sqlite",
]
php artisan migrate --database=sqlite --path=database/migrations/jobs
php artisan queue:work sqlite --tries=3