Laravel mail: pass string instead of view
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});
For Html emails
Mail::send(array(), array(), function ($message) use ($html) { $message->to(..) ->subject(..) ->from(..) ->setBody($html, 'text/html');});
The Mailer class passes a string to addContent
which via various other methods calls views->make()
. As a result passing a string of content directly won't work as it'll try and load a view by that name.
What you'll need to do is create a view which simply echos $content
// mail-template.php<?php echo $content; ?>
And then insert your string into that view at runtime.
$content = "Hi,welcome user!";$data = [ 'content' => $content];Mail::send('mail-template', $data, function() { });