如何在 laravel 上缓存电子邮件 html?
How to cache email html on laravel?
我正在使用 laravel 框架,我需要将 html 保存到缓存文件,.html 或其他文件以便在浏览器上显示而不是 link在时事通讯电子邮件中单击。 (link:在浏览器中查看电子邮件)。
在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。
在浏览器中查看电子邮件 link 就像地址一样。com/email/?html=gbfvisbiudoanlfdlsakdnlsakndlasn
你可以使用Sending e-mail in Laravel with custom 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!');
});
代码未经测试,但我相信您已经掌握了原理。
我正在使用 laravel 框架,我需要将 html 保存到缓存文件,.html 或其他文件以便在浏览器上显示而不是 link在时事通讯电子邮件中单击。 (link:在浏览器中查看电子邮件)。
在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。
在浏览器中查看电子邮件 link 就像地址一样。com/email/?html=gbfvisbiudoanlfdlsakdnlsakndlasn
你可以使用Sending e-mail in Laravel with custom 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!');
});
代码未经测试,但我相信您已经掌握了原理。