PHP code example of laratusk / laravel-mailgun-multi
1. Go to this page and download the library: Download laratusk/laravel-mailgun-multi library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
laratusk / laravel-mailgun-multi example snippets
// Without this package: calling code must select the right mailer manually
Mail::mailer('mailgun-acme')->to('[email protected]')->send($mailable);
// With this package: just send — transport is reconfigured automatically
Mail::to('[email protected]')->send($mailable);
'mailgun' => [
'domain' => env('MAILGUN_DOMAIN'),
'secret' => env('MAILGUN_SECRET'),
'endpoint' => env('MAILGUN_ENDPOINT', 'api.mailgun.net'),
'domains' => [
'acme.com' => [
'domain' => 'mg.acme.com',
'secret' => 'acme-mailgun-secret',
'endpoint' => 'api.eu.mailgun.net',
],
'awesome.app' => [
// Only override the secret; domain and endpoint fall back to global defaults
'secret' => 'awesome-secret',
],
],
],
'mailgun' => [
// ...
'log_domain_switches' => true, // logs debug info on each transport reconfiguration
],
use Laratusk\LaravelMailgunMulti\Contracts\MailgunSenderPropertiesResolver;
use Laratusk\LaravelMailgunMulti\DataObjects\MailgunSenderProperties;
class MyCustomResolver implements MailgunSenderPropertiesResolver
{
public function resolve(string $senderDomain): MailgunSenderProperties
{
// Fetch config from database, cache, or any source
return new MailgunSenderProperties(
domain: 'mg.' . $senderDomain,
secret: 'my-secret',
endpoint: 'api.mailgun.net',
);
}
}
use Laratusk\LaravelMailgunMulti\Contracts\MailgunSenderPropertiesResolver;
$this->app->bind(MailgunSenderPropertiesResolver::class, MyCustomResolver::class);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.