mabasic/mailer

This package is abandoned and no longer maintained. No replacement package was suggested.

Laravel 4 package for more efficient email sending inspired by Laracasts.

2.0.0 2015-06-06 20:56 UTC

This package is not auto-updated.

Last update: 2022-02-01 12:36:33 UTC


README

Laravel 4 package for more efficient email sending inspired by Laracasts lessons:

What does it exactly do?

It enables you to write this:

$this->contactMailer->send($data);

from your controller, instead of doing this:

Mail::queue($view, $data, function($message) use($email, $subject)
{
    $message->to($email)->subject($subject);
});

every time you want to send an email.

Installation

From your project root type:

composer require mabasic/mailer

Usage

Create a class for specific case like so:

<?php namespace Acme\Mailers;

use Mabasic\Mailer\Mailer;

class ContactMailer extends Mailer {

    public function send($data)
    {
        $view = 'emails.contact';
        $subject = 'Test';
        $email = 'test@test.com';

        $this->sendTo($email, $subject, $view, $data);
    }

}

Then in your controller you can inject it and use it like so:

<?php

use Acme\Mailers\ContactMailer;

class MailerController extends \BaseController {

    protected $contactMailer;

    function __construct(ContactMailer $contactMailer)
    {
        $this->contactMailer = $contactMailer;
    }

    public function sendMail()
    {
        // Get some data for the email, like user name, message, etc ...

        $data = [
            'name' => 'John Doe',
            'comment' => 'Hello, nice to meet you.'
        ];

        $this->contactMailer->send($data);

        return 'ok';
    }

}