m4rc377/mail

Use Illuminate Mail outside Laravel.

v1.0.0 2020-09-19 13:37 UTC

This package is auto-updated.

Last update: 2024-04-23 14:26:01 UTC


README

This is fork from hazzardweb/mail.

Installation

composer require m4rc377/mail

Usage

use m4rc377\Mail\Mail;
use Illuminate\Container\Container;
use Illuminate\Config\Repository as Config;

// Create a container and config repository.
$app = new Container;
$app['config'] = new Config;

// Set the mail & services configuration.
$app['config']['mail'] = require 'config/mail.php';
$app['config']['services'] = require 'config/services.php';

$mail = new Mail($container);

// Set the storage path used by the views.
$mail->setViewStoragePath(_DIR__.'/path/to/views');

// Make the instance available globally via static methods (optional).
$mail->setAsGlobal();

// Create a class alias (optional). 
$mail->classAlias();

Using The Mailer

Mail::send('emails.welcome', ['key' => 'value'], function ($message) {
    $message->to('foo@example.com', 'John Smith')->subject('Welcome!');
});

The rest is the same as Laravel.

Providing A Custom View Factory

To provide a custom view factory register a view binding to the container.

The view factory must implement Illuminate\Contracts\View\Factory and the view Illuminate\Contracts\View\View (or at least to have a render method).

$container['view'] = new CustomViewFactory();