First, lets install Mailer driver:
"symfony/brevo-mailer": "^7.0"
Now lets configure our Mailer. First put this code inside boot()
method in your AppServiceProvider.php
:
public function boot(): void
{
//...
$this->app['mail.manager']->extend('brevo', function ($config) {
$configuration = $this->app->make('config');
return (new BrevoTransportFactory())->create(
Dsn::fromString($configuration->get('services.brevo.dsn'))
);
});
}
Here you can see services.brevo.dsn
config. I created file config/services
and there the following code:
return [
'brevo' => [
'dsn' => env('MAILER_DSN'),
],
];
Now lets go to config/mail.php
and setup our mailer:
'mailers' => [
// ...
'brevo' => [
'transport' => 'brevo',
],
]
Then we should create our Email:
class WelcomeMail extends Mailable
{
use Queueable, SerializesModels;
public function __construct(
public readonly string $username
) {
}
public function build(): self
{
$this->withSymfonyMessage(function (Email $message) {
$message->getHeaders()
->addHeader('templateId', 1)
->addParameterizedHeader('params', 'params', [
'customerName' => $this->username,
]);
});
return $this;
}
}
Here we add headers with templateId
and custom data. Brevo uses custom data to fill your variables inside your templates.
Feel free to ask any questions in comments 👇
Follow me on X (prev Twitter)
Top comments (0)