我在Laravel PHP中有一封自动电子邮件,通知用户特定产品已过期。
我想要包含一个base64图像,它应嵌入电子邮件本身。
是否可以使用Laravel在basedown电子邮件中嵌入base64图像?
如果是这样的话?
以下是电子邮件降价刀片模板:
@component('mail::message')
![Logo][logo]
[logo]: {{asset('frontend/img/core-img/logo-dark.png')}} "Logo"
**Product Expiry**
Dear {{$userName}},
This is to inform you that your product **{{$listingName}}**.
Your item was removed from the Market Place. Should you wish to re-list the item kindly do so from the app.
![alt]{{$listingImage}}
Should you require any information or need professional assistance kindly get in touch:
@component('mail::button', ['url' => ''])
Contact Us
@endcomponent
Thanks,<br>
# **{{ config('app.name') }} Team**
![App Icon|100x100]({{asset('frontend/img/core-img/app-logo.png')}})
@endcomponent
并且是此电子邮件模板的类:
<?php
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
class ListingExpiryEmail extends Mailable
{
use Queueable, SerializesModels;
protected $user_name;
protected $listing_name;
protected $listing_image;
/**
* Create a new message instance.
*
* @return void
*/
public function __construct($user_name, $listing_name, $image)
{
$this->user_name = $user_name;
$this->listing_name = $listing_name;
$this->listing_image = $image;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->subject('MyHurryApp Listing Expiry')->markdown('emails.listings.listingexpiryemail', [
'userName' => $this->user_name,
'listingName' => $this->listing_name,
'listingImage' => $this->listing_image
]);
}
}
谢谢
经过进一步的研究,我发现这是不可能的。
Markdown文档只是一个文本文件,文本编辑器不知道如何处理“文本”中的二进制图像。
说过可能有办法绕过这个限制:
在某种意义上,有像MIME和base64这样的方法将二进制数据编码成文本文件,但是大多数文本编辑器和Markdown渲染器都不知道如何处理包含Markdown文本部分和base64编码图像的MIME编码文档部分。
但我仍在寻找可能的解决方案。
如果有人可以进一步指导我将非常感激。
谢谢
这适合我
<img src="data:image/png;base64,{base64_encode(file_get_contents(public_path('/image/logo.png')))}}">