Skip to content

Instantly share code, notes, and snippets.

@gbrock
Created November 12, 2015 15:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gbrock/80d351f7a28c4772a6b0 to your computer and use it in GitHub Desktop.
Save gbrock/80d351f7a28c4772a6b0 to your computer and use it in GitHub Desktop.
Laravel 5.1 example of abstracting e-mail sending into its own dedicated class
<?php
namespace App\Extensions;
use Illuminate\Support\Facades\Mail;
class Postmaster {
/**
* Send an e-mail to a specific user. Pass in the User object,
* the name of the view, any data needed by the view, and the subject.
*/
public static function toUser($user, $view, $data, $subject = false)
{
Mail::send($view, $data, function ($message) use ($user, $subject) {
if ($user->email) {
$message->to($user->email, $user->name)->subject($subject);
} else {
return false;
}
});
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment