Laravel 从MailMessage对象获取内容
我正在尝试创建一个系统,该系统将根据用户的帐户自动记录我的网站发送给用户的任何电子邮件通知的内容 我通过监听Laravel 从MailMessage对象获取内容,laravel,markdown,Laravel,Markdown,我正在尝试创建一个系统,该系统将根据用户的帐户自动记录我的网站发送给用户的任何电子邮件通知的内容 我通过监听NotificationSent事件来实现这一点,该事件使我能够轻松访问应通知的(我要存储日志条目的对象)和通知(定义已发送消息的对象) 使用这些工具,我可以获得MailMessage对象,但我不知道如何渲染它。我希望它会有一个渲染方法,但我找不到。可能还有其他对象接受MailMessage并进行渲染。有什么线索吗 理想情况下,我希望电子邮件的纯文本版本(降价) 感谢您的帮助我找到了一个解
NotificationSent
事件来实现这一点,该事件使我能够轻松访问应通知的
(我要存储日志条目的对象)和通知
(定义已发送消息的对象)
使用这些工具,我可以获得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对象实例化时发生的事情给出正确的解释,我将不胜感激)