Reputation: 13
I'm trying to display image (uploaded in my web app) transported from LARAVEL in the email message.
Picture of received email:
Currently, I achieved to show the image as an attachment of an email message, but my goal is to display the image as a cover photo of an email. The content of the email message is developed within the catalogEmail.blade.php file.
CatalogController.pho
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('[email protected]')->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 App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;
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('[email protected]')->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>
Upvotes: 1
Views: 2983
Reputation: 4153
You must prepend the tdl to the image source address. Something like this:
<img src="http://example.com/{{public_path('uploads/catalogs/pictures/'.$data['post_thumbnail2'])}}"/>
Upvotes: 1