Lansana Camara
Lansana Camara

Reputation: 9873

Laravel Mailer: attching/displaying image in base64 not working properly in Gmail

I am attempting to attach an image/show the image in the email template using base64 so that I don't have to store the file, but I am not having luck.

The image gets successfully attached with the proper file size/name in Gmail, however the image is broken and never actually shows.

The image set in the img tag on the email template also does not display properly.

Rubric for both examples:

The data field is the base64 string, which looks like: data:image/gif;base64,AJHDJsdlksdAK....

The name is the name of the file.

The mime would be like image/gif.

Here is what I am trying the template (the first shows a broken image, the second renders the image with the proper base64 string but everything is in plain text as opposed to being interpreted as HTML):

<img src="{{$message->embedData($inputs['picture']['data'], $inputs['picture']['name'])}}">
<img src="{{$inputs['picture']['data']}}">

Here is the Mailer class:

return $this->from('[email protected]')
                ->attachData($picture['data'], $picture['name'], [
                    'mime' => $picture['mime']
                ])
                ->view('form.submitted')
                ->with($data);

What am I doing wrong here? I am following everything exactly as it shows in the Laravel Documentation for mail under Attachments.

Upvotes: 0

Views: 938

Answers (1)

Peyman
Peyman

Reputation: 312

You have to decode data once attaching: ->attach(base64_decode($picture['data']), 'Blah'))

Upvotes: 1

Related Questions