Mail

Introduction

We follow Laravel Mail very closely. Generally speaking the functionality is the same but we add a few things on top of it.

Laravel Mail{.link}

Sending Mail

Use Laravel's Mailer instance or the Mail facade to send email. To send a message, use the to method on the Mailer. The to method accepts an email address, a user instance, or a collection of users. If you pass an object or collection of objects, the mailer will automatically use their email and name properties when setting the email recipients, so make sure these attributes are available on your objects. Once you have specified your recipients, you may pass an instance of your mailable class to the send method:

<?php

namespace App\Http\Controllers;

use Anomaly\ExampleModule\Order\OrderModel;
use Anomaly\ExampleModule\Order\Mail\OrderShipped;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Mail;
use App\Http\Controllers\Controller;
use Illuminate\Contracts\Mail\Mailer;
use Illuminate\Http\Response;

class OrderController extends Controller
{
    /**
     * Ship the given order.
     *
     * @param  Request $request
     * @param  int $orderId
     * @return Response
     */
    public function ship(Request $request, Mailer $mailer, $orderId)
    {
        $order = OrderModel::findOrFail($orderId);

        // Ship order...

        $mailer->to($request->user())->send(new OrderShipped($order));
    }
}

You are not limited to just specifying the "to" recipients when sending a message. You are free to set "to", "cc", and "bcc" recipients all within a single, chained method call:

Mail::to($request->user())
    ->cc($moreUsers)
    ->bcc($evenMoreUsers)
    ->send(new OrderShipped($order));