如何在 Laravel Markdown 电子邮件中嵌入 Base64 图像

Mat*_*hew 1 email markdown base64 laravel

我在 Laravel PHP 中有一封自动电子邮件,通知用户特定产品已过期。

我想包含一个应该嵌入到电子邮件本身中的 base64 图像。

是否可以使用 Laravel 在 Markdown 电子邮件中嵌入 Base64 图像?

如果是这样怎么办?

以下是电子邮件 Markdown 刀片模板:

@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
Run Code Online (Sandbox Code Playgroud)

是此电子邮件模板的类:

<?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
        ]);
    }
}
Run Code Online (Sandbox Code Playgroud)

谢谢

Mar*_*ala 5

这对我有用

<img src="data:image/png;base64,{{base64_encode(file_get_contents(public_path('/image/logo.png')))}}">
Run Code Online (Sandbox Code Playgroud)