问题描述
我需要发送电子邮件,但是我已经生成了HTML,我不想使用laravel刀片,因为我需要将CSS Inliner应用到HTML中,所以这是我如何生成html: ($ viewData){
// code
$ html = View :: make('email。通知',$ viewData) - > render();
$ this-> cssInliner-> setCSS($ this-> getCssForNotificationEmail());
$ this-> cssInliner-> setHTML($ html);
return $ this-> cssInliner-> convert();
}
所以,要发送Laravel的邮件,你通常会这样做: / p>
Mail :: send('emails.welcome',$ data,function($ message)
{
$ message-> to('[email protected]','John Smith') - > subject('Welcome!');
});
但我不想传递一个视图,我已经有了html,我该怎么办那么?
如果我想要达到的目标是正确的,为了得到这个结果,我创建了一个名为echo的视图。 php和里面只是回调$ html。
将您的html分配给$ data ['html']。
然后,将$ data ['html']传递到回声视图。
Mail :: send('emails.echo' ,$ data,function($ message)
{
$ message-> to('[email protected]','John Smith') - > subject('Welcome!');
});
让我知道你是如何得到的。
I need to send e-mails but I already have the HTML generated, I don't want to use laravel blade because I need to apply a CSS Inliner to the HTML, so this is how i generate the html:
getRenderedView($viewData) {
//code
$html = View::make('email.notification', $viewData)->render();
$this->cssInliner->setCSS($this->getCssForNotificationEmail());
$this->cssInliner->setHTML($html);
return $this->cssInliner->convert();
}
So, to send the mail with Laravel you usually do something like this:
Mail::send('emails.welcome', $data, function($message)
{
$message->to('[email protected]', 'John Smith')->subject('Welcome!');
});
But I don't want to pass a view, I already have the html, how can I do that?
If I'm right in what you want to achieve, to get round this I created a view called echo.php and inside that just echo $html.
Assign your html to something like $data['html'].
Then below pass your $data['html'] to the echo view.
Mail::send('emails.echo', $data, function($message){ $message->to('[email protected]', 'John Smith')->subject('Welcome!');});
Let me know how you get on.
这篇关于使用自定义HTML在Laravel中发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!