PHP code example of crystoline / laravel-custom-mail-provider

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

    

crystoline / laravel-custom-mail-provider example snippets




return [
    'default' => env('MAIL_MAILER', 'smtp'),
    'mailers' => [
        'smtp' => [
            'transport' => 'smtp',
            'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
            'port' => env('MAIL_PORT', 587),
            'encryption' => env('MAIL_ENCRYPTION', 'tls'),
            'username' => env('MAIL_USERNAME'),
            'password' => env('MAIL_PASSWORD'),
            'timeout' => null,
            'auth_mode' => null,
        ],
        #### Add this
        'custom-mailer' => [
            'transport' => 'crystoline'
        ]
        
        ####

        
    ],

    

];


use Illuminate\Mail\Transport\Transport;

class MyMailTransport extends Transport
{

    public function send(Swift_Mime_SimpleMessage $message, &$failedRecipients = null)
    {

        $url = 'https://my.custome.email.service';

        $data = [

            "toAddress" => implode(',', array_keys($message->getTo())),
            "subject" => $message->getSubject(),
            "body" => $message->getBody()
        ];
       #Send mail logic here :)

    }
}

namespace App\Resolvers;

use App\Services\MyCustomMailTransport;
use Crystoline\CustomMailProvider\Interfaces\ICustomMailerResolver;

class MyMailTransportResolver implements ICustomMailerResolver
{

    function resolve(): \Illuminate\Mail\Transport\Transport
    {
        return new MyCustomMailTransport();
        #   You can have multiple mail transport here
        #   swich(condition){
        #   case A: return new MyCustomMailTransport1();
        #   case B: return new MyCustomMailTransport2();
        #   case C:
        #   default:
        #      return new MyCustomMailTransport3();
        #   }
    }
}


namespace App\Providers;

use App\Resolvers\MyMailTransportResolver;
use Crystoline\CustomMailProvider\Interfaces\ICustomMailerResolver;

use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
	    
    }

    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        $this->app->bind(ICustomMailerResolver::class, MyMailTransportResolver::class );
    }
}