laravel - 从 MailMessage 对象获取内容
问题描述
我正在尝试创建一个系统,该系统将根据他们的帐户自动记录我的网站发送给用户的任何电子邮件通知的内容。
我通过监听NotificationSent
事件来做到这一点,这使我可以轻松访问Notifiable
(我想要存储我的日志条目Notification
的对象)和(定义已发送消息的对象)。
使用这些我可以得到MailMessage
对象,但我不知道如何渲染它。我希望它有一个渲染方法,但我找不到。大概还有其他一些对象接受MailMessage
并进行渲染。有什么线索吗?
理想情况下,我想要电子邮件的纯文本版本(降价)
谢谢你的帮助
解决方案
我有一个正在做我想做的事情的解决方案。我蚕食了我为其他东西编写的一些代码,这让我走了很长一段路。有些步骤我不完全理解,所以这里可能会有一些不必要的膨胀:
class LogNotification
{
public function handle(NotificationSent $event)
{
//getting the MailMessage object
$mailMsg = $event->notification->toMail($event->notifiable);
//I think this is getting the additional variables from the
//MailMessage that are needed to render the view
$msgData = array_merge($mailMsg->toArray(),$mailMsg->viewData);
//I don't fully understand this. I get that the Markdown object is
//going to do the rendering, but I don't know why it needs to be
//instantiated with an empty View object
$markdown = new \Illuminate\Mail\Markdown(view(), config('mail.markdown'));
//Pass the renderText method the path to the markdown, and the message data
$msgContent = $markdown->renderText($mailMsg->markdown, $msgData);
}
}
希望这对某人有所帮助(如果有人可以对实例化 Markdown 对象时发生的事情提供适当的解释,我将不胜感激)。
推荐阅读
- reactjs - Persona - onRenderPrimaryText - 传递 addt'l 参数?
- javascript - 如何在 Jasmine 中强制执行默认超时间隔?
- java - 为什么这是一个静态上下文?
- python - 为什么应用于实例的 Python 帮助函数在某些情况下会返回有关父类的页面,而在其他情况下则不返回?
- css - 绝对 div 是否有可能具有宽度:自动,并且还忽略它的父宽度?
- java - SimpleDateFormat 导致无法解析的错误
- python - 如何基于 QTimer 更新 QPainter 像素图
- c# - 运行函数
在使用 .Net 的计时器上 - javascript - 有没有办法使用 JavaScript (Vue.js) 将 Java 应用程序(游戏)实现到网站中
- sql - 为每位客户提供多项交易