Laravel:如何将图像作为内容而不是附件嵌入电子邮件中
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26692705/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel: How to embed image in an email as a content and not as an attachment
提问by BlackPearl
I have searched for ways to embed an image in an email sent with Laravel. The method I have found which most people use is to embed the image as an attachment.
我已经搜索了在使用 Laravel 发送的电子邮件中嵌入图像的方法。我发现大多数人使用的方法是将图像作为附件嵌入。
<img src="{{$message->embed(asset('assets/img/logo.png'))}}" style="padding:0px; margin:0px" />
Is there a way to embed an image without it being an attachment? I tried converting the image to base64 strings but that didn't even work.
有没有办法在没有附件的情况下嵌入图像?我尝试将图像转换为 base64 字符串,但这甚至不起作用。
回答by lukasgeiter
Whether its a good thing or not...
不管是好事还是坏事...
You nearly have it. I suppose the problem is that the asset()
function is generating a full url and Laravel need the path to the file. Official Doc
你几乎拥有它。我想问题是该asset()
函数正在生成一个完整的 url,而 Laravel 需要文件的路径。官方文件
Try this:
尝试这个:
<img src="{{ $message->embed('assets/img/logo.png') }}" style="padding:0px; margin:0px" />