Downloads
Stars
Version
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.
From your project root type:
composer require mabasic/mailer
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 = '[email protected]';
$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';
}
}