如何在laravel上缓存电子邮件html


How to cache email html on laravel?

我与laravel框架工作,我需要保存html缓存文件,.html等文件显示在浏览器上比链接点击在通讯电子邮件。(链接:在浏览器中查看邮件)。

在integration.blade.php中包含@include('emails/header')@include('emails/footer')

这是邮件发送代码:

Mail::send('emails/integration', array('type' => ucfirst($type)), function($message) use ($type)
    {
    $message->to( Auth::user()->email, Auth::user()->fullname)->subject('Successful name and '.ucfirst($type).' store integration!');
    });

之后我需要缓存html。

在浏览器中查看电子邮件链接为address.com/email/?html=gbfvisbiudoanlfdlsakdnlsakndlasn

你可以使用在Laravel中发送电子邮件的主要原理来自定义HTML,但是在创建视图之后你可以缓存它:

$minutes = ...
$viewData = [
    'type' => ucfirst($type)
];
$html = Cache::remember('email/integration', $minutes, function()
{
    return View::make('email/integration', $viewData)->render();
});
Mail::send('emails.echo', ['html' => $html], function($message) use ($type)
{
    $message->to(Auth::user()->email, Auth::user()->fullname)->subject('Successful name and '.ucfirst($type).' store integration!');
});

代码是未经测试的,但我相信你明白的原则。