Laravel-Mail: How to pass ->attachData to view
The attachData
method adds an email attachment and doesn't work for inline images. You need to add your image data to your $data_content variable and refer to it from there:
$data_content['attachedImage'] = ...; // Get the regular data of the image, not the base64 version
and then in your template use the embedData
method:
<img src="{{ $message->embedData($attachedImage, 'test.png') }}" align="right" width="150px" height="100px"/>
If you need to leave the data as base64 then just pass the data into $data_content
as base64 and use it this way:
<img src="data:image/png;base64,{{ $attachedImage }}" align="right" width="100px" height="100px"/>
You can pass data to your view as the second
argument of send()
method and it needs to be an array
of data. Change your controller to -
Mail::send('mailtransaction', ['data_content'=>$data_content,'base64'=>$base64], function($msg) use ($to, $issueType){ $msg->to($to); // change this upon finishing $msg->attachData($request->getBase64, 'test.png', ['mime'=>'image/png']); $msg->subject($issueType); });
And in your view, you can access data_content
and base64
as-
{{$data_content}}{{$base64}}