Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

AydenWH's avatar

Attach image into the email

Hi everyone.

I am trying to attach an image to the email by which can be found in my local storage.

It displays nothing whenever I tried to use asset() to attach the image to the email.

I tried to use $message and it is not working, perhaps it is because I am not using Markdown template?

This is my Mail.php

$email = $this->view('email.voucher')
            ->with([
                'voucher' => $this->voucher_information,
                'barcode' => $this->barcode,
                'recipient' => $this->recipient,
                'gift_message' => $this->gift_message
            ])
            ->from('[email protected]', 'Purchase')
            ->replyto('[email protected]', 'Purchase')
            ->subject('Giftbox EVoucher');

In my voucher.blade.php template

!DOCTYPE
<html>
...
<img src="{{ asset('images/' . $barcode)) }}" alt="Barcode">
...
</html>
0 likes
2 replies
burlresearch's avatar

asset() is simply a helper to generate a fully qualified URL to the path supplied, relative to the public/ folder in your application.

  1. The first thing to do is to verify that the actual asset is there (or else it won't show up).

  2. Then ensure the URL that gets generated is accessible from the place the mail gets read. IE if you're reading your mail @ Mailtrap (on the internet) then your image URL must resolve, publicly, on the internet. References to assets on your local storage, obviously, will not resolve.

Given that you are NOT using markdown email, perhaps what you are looking for is to embed the image in your email:

https://laravel.com/docs/5.5/mail#inline-attachments

This may be achieved with this command:

    <img src="{{ $message->embed($pathToFile) }}">
3 likes

Please or to participate in this conversation.