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

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

问题描述

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



如何将简单的内容传递给电子邮件? / p>

示例:

  $ content =欢迎用户! ; 

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


解决方案

Mailer类将一个字符串传递给 addContent 通过各种其他方法调用 views-> make()。因此,直接传递一串内容将无法正常工作,因为它会尝试加载该名称的视图。



您需要做的是创建一个视图,只是回想起$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ php
<?php echo $ content; ?>

然后在运行时将您的字符串插入该视图。

  $ content =欢迎用户!; 

$ data = [
'content'=> $ content
];

Mail :: send('mail-template',$ data,function(){});


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

解决方案

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

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

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