是否可以在Laravel中的HTML电子邮件中包含图像

cch*_*man 5 html php email laravel blade

我目前正在尝试通过Laravel发送HTML电子邮件Mail::send().我正在使用的视图是一个Blade模板,但我不太确定如何将图像包含在电子邮件正文中.

在我的模板中,我有

<h4>You have successfully updated your Session!</h4>

@if ( $old_date != $date)
    <p>You have changed from {{ $old_date }} to {{ $date }}</p>
@endif

<p>If you have any questions or concerns, please contact the Office of Admissions</p>

{{ HTML::image('/images/full-logo.png', 'logo') }}
Run Code Online (Sandbox Code Playgroud)

但是,我的电子邮件中只显示了电子邮件正文中的链接图标.是否可以将图像作为参数传递给视图?在我发送电子邮件的控制器中,我有

$data = array (
                        'first_name'    => $student->first_name,
                        'last_name'     => $student->last_name,
                        'date'          => $day,
                        'old_date'      => $old_day,
                );


Mail::send ( '/emails/create_student', $data, function ($message) {
    ...
} );
Run Code Online (Sandbox Code Playgroud)

所以我不确定是否可以通过$data阵列包含图像.

小智 7

这个对我有用:图像在电子邮件视图中声明

<img src="{{ $message->embed(public_path() . '/resources/icon/icon.png') }}" alt="" />
Run Code Online (Sandbox Code Playgroud)

来自Laravel doc "A $ message变量总是传递给电子邮件视图,并允许内联嵌入附件."


Lim*_*nte 2

HTML::image()生成图像的绝对路径,如下所示:

http://yoursite.dev/image.png
Run Code Online (Sandbox Code Playgroud)

这在您当地的环境中完美运行。

邮件客户端(例如 Gmail)将使用如下内容覆盖图像路径:

http://images.gmail.com/?src=http://yoursite.dev/image.png
Run Code Online (Sandbox Code Playgroud)

显然,第 3 方服务无法访问您的本地域,因此您会看到损坏的图像。

作为解决方案,您可以将图像上传到 Amazon AWS 等第三方服务,并将上传图像的链接传递到电子邮件模板。