Laravel API mailer
Sending e-mail from different mail service API is a painful task because they use their own payload structure which is different according to the e-mail service provider. In this situation, the API mailer package for Laravel will give a clean syntax generalize payload structure for sending e-mail from a different e-mail service provider like SendGrid, Mailgun etc. Let's explore the API mailer package.
GitHub repository: https://github.com/haruncpi/laravel-api-mailer
Installation
composer require haruncpi/laravel-api-mailer
Configuration
Now publish the api-mailer.php
configuration file to your project config directory by following this command.
php artisan vendor:publish --provider="Haruncpi\LaravelApiMailer\ApiMailerServiceProvider" --tag="config"
.env file configarations
Currently, API mailer supports SendGrid and Mailgun. The default driver is mailgun
. You can change it by putting APIMAILER_DEFAULT
into .env file. There are env file entities you can configure.
APIMAILER_DEFAULT=mailgun
APIMAILER_FROM_NAME=Example
APIMAILER_FROM_EMAIL=abc@example.com
APIMAILER_SENDGRID_APIKEY=your_sendgrid_apikey
APIMAILER_MAILGUN_APIKEY=your_mailgun_apikey
APIMAILER_MAILGUN_DOMAIN=mailgun_domain
Usages
Single e-mail
$payload = ['to' => 'alex@example.com', 'subject' => 'Hello Friend', 'body' => 'How are you'];
$response = apiMailer()->send($payload);
Multiple e-mails
$receivers = ['a@example.com','b@example.com', ...]
$payload = ['to' => $receivers, 'subject' => 'Hello Friends', 'body' => 'Your HTML body'];
$response = apiMailer()->send($payload);
You can use ApiMailer facade
use Haruncpi\LaravelApiMailer\Facades\ApiMailer;
$response = ApiMailer::send($payload);
Response format
//success
{
success: true,
message: "successfully send"
}
//fail
{
success: false,
message: "reason for failure"
}
Hope the Laravel API mailer package will help you to send e-mail using different e-mail services with simple & clean generalize syntax. If you find this package helpful then support it on GitHub API mailer repository and don't forget to share it with others.