PHP code example of elfsundae / laravel-multi-mail

1. Go to this page and download the library: Download elfsundae/laravel-multi-mail 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/ */

    

elfsundae / laravel-multi-mail example snippets




namespace App\Providers;

use Illuminate\Mail\TransportManager;
use Illuminate\Support\ServiceProvider;
use App\Support\Mail\FooTransport;

class AppServiceProvider extends ServiceProvider
{
    public function register()
    {
        $this->app->resolving(function (TransportManager $manager) {
            $manager->extend('foo', function ($app) {
                $config = $app['config']['services.foo'];

                return new FooTransport($config['key'], $config['secret']);
            });
        });
    }
}

Mail::mailDriver('mailgun')->to($user)->send(new OrderShipped($order));



namespace App\Providers;

use ElfSundae\Multimail\Mailer;
use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{
    public function register()
    {
        $this->app->resolving(function (Mailer $mailer) {
            $mailer->registerSendingMessageHandler(function ($message) {
                $message->addBcc('[email protected]');
            });
        });
    }
}

$mailer->registerSendingMessageHandler(
    function (CacheRepository $cache, SwiftMailerManager $swift, $message, $mailer) {
        //
    }
);

$mailer->registerSendingMessageHandler('App\Mail\Handler\SendingMessage');

$mailer->registerSendingMessageHandler('App\Mail\Handler\SendingMessage@sendingMailHandler');

$mailer->registerSendingMessageHandler(function ($message) {
    if (preg_match_all(
        '#@(.+\.)?(qq.com|126.com|163.com|sina.com|sina.cn)$#im',
        implode(PHP_EOL, MessageHelper::getRecipients($message))
    )) {
        return 'directmail';
    }
});

$this->updateMailConfig();

Mail::getSwiftMailerManager()->resetMailers();