Giter Site home page Giter Site logo

laravel-switchable-mail's Introduction

laravel-switchable-mail

It makes Laravel be able to maintain multiple mail drivers at the same time, and be able to send to different mail addresses with specified mail drivers as configured at runtime automatically.

Instructions

English

中文简体

Installation

  1. Install this package using the Composer manager:

    composer require kevinzheng/laravel-switchable-mail
  2. Replace Illuminate\Mail\MailServiceProvider::class with KVZ\Laravel\SwitchableMail\MailServiceProvider::class in the config/app.php file.

  3. Publish configuration file:

    php artisan vendor:publish --tag=switchable-mail

Configuration

It uses the MAIL_DRIVER configured in .env as the default mail driver, for those addresses you want to send to with specified mail drivers, configure it at switchable-mail.php. You should install the mail drivers not provided by Laravel at the meantime, such as Aliyun Direct Mail and SendCloud:

```php
// 'directmail' => [
//     'qq.com', '163.com', '126.com', 'sina.com', 'sina.com.cn', 'sohu.com',
// ],

// 'mailgun' => [
//     'example.com',
// ],

// to use with Mail::sendThrough('another_smtp', ...);

// 'another_smtp' => [
//  'driver'   => 'smtp',
//  'host'     => 'smtp.example.com',
//  'port'     => 2525,
//  'username' => 'non_default_user',
//  'password' => 'user_password',
//],
```

Two mail drivers are available:

laravel-directmail

laravel-sendcloud

Usage

If you want to send mail through different driver, just call method Mail::sendThrough($driver, $view, array $data, $callback)

Example:

...
$email = '[email protected]';
$subject = 'mail subject';

Mail::sendThrough('another_smtp', 'mail.welcome', ['email' => $email], 
  function($mail) use ($email, $subject) {
	$mail
	  ->from(config('mail.from.address'), config('mail.from.name'))
	  ->to($email)
	  ->subject($subject);
});

Thanks to

ElfSundae

laravel-switchable-mail's People

Contributors

elfsundae avatar kvzn avatar ranger-x avatar

Watchers

 avatar  avatar

Forkers

beamjet

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.