Laravel 邮件:传递字符串而不是视图 [英] Laravel mail: pass string instead of view

查看:36
本文介绍了Laravel 邮件:传递字符串而不是视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 Laravel 发送确认电子邮件.laravel Mail::send() 函数似乎只接受系统上文件的路径.问题是我的邮件模板存储在数据库中,而不是系统上的文件中.

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?

示例:

$content = "Hi,welcome user!";

Mail::send($content,$data,function(){});

推荐答案

更新:在 Laravel 5 中,您可以使用 raw 代替:

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
});

这篇关于Laravel 邮件:传递字符串而不是视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆