首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从MailMessage对象获取内容

从MailMessage对象获取内容
EN

Stack Overflow用户
提问于 2018-07-25 23:23:46
回答 1查看 100关注 0票数 0

我正在尝试创建一个系统,将自动记录我的网站发送给用户的任何电子邮件通知的内容,针对他们的帐户。

我是通过侦听NotificationSent事件来实现这一点的,该事件为我提供了对Notifiable (我希望存储日志条目的对象)和Notification (定义已发送消息的对象)的轻松访问。

使用这些,我能够获得MailMessage对象,但我不知道如何呈现它。我希望它有一个渲染方法,但我找不到一个。可能还有其他一些对象接受MailMessage并进行渲染。有什么线索吗?

理想情况下,我想要电子邮件的纯文本版本( markdown)

谢谢你的帮助

EN

回答 1

Stack Overflow用户

发布于 2018-07-26 16:49:33

我有一个解决方案,就是做我想做的事情。我窃取了我为其他东西写的一些代码,这让我走了很长一段路。有一些步骤我不完全理解,所以这里可能会有一些不必要的臃肿:

代码语言:javascript
复制
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对象时发生的事情提供适当的解释,我将不胜感激)。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51522589

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档