First of all, I know laravel already has a wrapper for Mailgun but laravel doesn't support Mailgun batch sending so I HAVE to use Mailgun php sdk in laravel which I finally got working, however I think having to do the following:
$mailgun = Mailgun::create(config('mail.mailgunSecret'));
before sending the messages with mailgun is a little repetitive, with other API like Stripe I make a serviceprovider and instantiate it like this:
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Stripe\Stripe;
class StripeServiceProvider extends ServiceProvider
{
public function boot()
{
Stripe::setApiKey(config('services.stripe.secret'));
}
}
But I don't know if I'm able to do something like this with mailgun since this is how I'm sending mails currently.
$mailgun = Mailgun::create(config('mail.mailgunSecret'));
$result = $mailgun->sendMessage(config('mail.mailgunDomain'), [
'from' => config('mail.from'),
'to' => $emails,
'subject' => '%recipient.first% no te pierdas lo último de '.config('app.name'),
'html' => $html,
'recipient-variables' => '{ "example@gmail.com": {"first":"Gabriel", "id":1}, "example@gmail.com": {"first":"Silvia", "id":2} }'
]);
Any advice?