Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel mail: pass string instead of view

I want to send a confirmation e-mail using laravel. The laravel Mail::send() function only seems to accept a path to a file on the system. The problem is that my mailtemplates are stored in the database and not in a file on the system.

How can I pass plain content to the email?

Example:

$content = "Hi,welcome user!";  Mail::send($content,$data,function(){}); 
like image 378
nexana Avatar asked Oct 01 '14 11:10

nexana


2 Answers

update: In Laravel 5 you can use raw instead:

Mail::raw('Hi, welcome user!', function ($message) {   $message->to(..)     ->subject(..); }); 

This is how you do it:

Mail::send([], [], function ($message) {   $message->to(..)     ->subject(..)     // here comes what you want     ->setBody('Hi, welcome user!'); // assuming text/plain     // or:     ->setBody('<h1>Hi, welcome user!</h1>', 'text/html'); // for HTML rich messages }); 
like image 156
Jarek Tkaczyk Avatar answered Sep 23 '22 15:09

Jarek Tkaczyk


For Html emails

Mail::send(array(), array(), function ($message) use ($html) {   $message->to(..)     ->subject(..)     ->from(..)     ->setBody($html, 'text/html'); }); 
like image 39
Sajjad Ashraf Avatar answered Sep 21 '22 15:09

Sajjad Ashraf