如何在电子邮件中显示从Laravel发送的图像
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何在电子邮件中显示从Laravel发送的图像相关的知识,希望对你有一定的参考价值。
我正在尝试在电子邮件中显示从LARAVEL传输的图像(在我的Web应用程序中上传)。
收到的邮件图片:
目前,我实现了将图像显示为电子邮件的附件,但我的目标是将图像显示为电子邮件的封面照片。电子邮件的内容是在catalogEmail.blade.php文件中开发的。
目录Controller.php
function Sendcatalog (Request $request, $url){
$this->validate($request, [
'email' => 'required|email'
]);
$language=Language::where('url', '=', $url)->first();
if(count($language)==0){
abort(404);
}
$emailStorage= new EmailStorage;
$emailStorage -> email = $request -> input('email');
$emailStorage->save();
$catalog=Catalog::first();
$data = array(
'email' => $request->email,
'filename' => $catalog->file_name,
'title' => $catalog->title,
'content' => $catalog->content,
'post_thumbnail' => $catalog->post_thumbnail,
'post_thumbnail2' => $catalog->post_thumbnail2,
);
$visitorEmail=$request->email;
Mail::to('kajoswiss@gmail.com')->send(new SendCatalogInfo($data));
Mail::to($visitorEmail)->send(new SendCatalog($data));
return back()->with('successPost', 'You will get soon catalog on your email address');
}
Web.php
Route::post('/sendcatalog/{url}', 'CatalogController@Sendcatalog')->name('catalog.send');
SendCatalog.php(mail.php)
<?php
namespace AppMail;
use IlluminateBusQueueable;
use IlluminateMailMailable;
use IlluminateQueueSerializesModels;
use IlluminateContractsQueueShouldQueue;
class SendCatalog extends Mailable
{
use Queueable, SerializesModels;
/**
* Create a new message instance.
*
* @return void
*/
public function __construct($data)
{
$this->data = $data;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->from('kajoswiss@gmail.com')->subject('KAJO company')->attach(public_path('uploads/catalogs/pictures/'. $this->data['post_thumbnail2']))->view('email/catalogEmail')->with('data', $this->data);
}
}
CatalogEmail.blade.php
<h3>Hello, catalog {{ $data['title'] }}</h3>
<p>Hello, catalog {!! $data['contnet'] !!}</p>
<img src="{{public_path('uploads/catalogs/pictures/'.$data['post_thumbnail2'])}}"/>
Preuzmite katalog iz linka
<a href="{{asset('storage/upload/'.$data['filename'])}}" class="btn btn-hot text-capitalize btn-xs" download>Preuzmi fajl</a>
答案
您必须将tdl添加到图像源地址。像这样的东西:
<img src="http://example.com/{{public_path('uploads/catalogs/pictures/'.$data['post_thumbnail2'])}}"/>
以上是关于如何在电子邮件中显示从Laravel发送的图像的主要内容,如果未能解决你的问题,请参考以下文章
在 Laravel 中使用 MailChimp 发送常规电子邮件
对于从 java 程序发送的电子邮件,html 内容中的 png 图像未显示在 gmail 客户端上