我正在尝试创建一个系统,将自动记录我的网站发送给用户的任何电子邮件通知的内容,针对他们的帐户。
我是通过侦听NotificationSent事件来实现这一点的,该事件为我提供了对Notifiable (我希望存储日志条目的对象)和Notification (定义已发送消息的对象)的轻松访问。
使用这些,我能够获得MailMessage对象,但我不知道如何呈现它。我希望它有一个渲染方法,但我找不到一个。可能还有其他一些对象接受MailMessage并进行渲染。有什么线索吗?
理想情况下,我想要电子邮件的纯文本版本( markdown)
谢谢你的帮助
发布于 2018-07-26 16:49:33
我有一个解决方案,就是做我想做的事情。我窃取了我为其他东西写的一些代码,这让我走了很长一段路。有一些步骤我不完全理解,所以这里可能会有一些不必要的臃肿:
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对象时发生的事情提供适当的解释,我将不胜感激)。
https://stackoverflow.com/questions/51522589
复制相似问题