How to attach image to the email using symfony mailer?

177 views Asked by At

I need to add image into the email. My images are located inside the public folder. I have defined in my twig.yaml like this:

twig:
    globals:
        image_dir: '%kernel.project_dir%/public/images/logos'

    default_path: '%kernel.project_dir%/templates'
    debug: '%kernel.debug%'
    strict_variables: '%kernel.debug%'
    exception_controller: null

Now in my twig.html file, I am calling image like below.

<img src="{{ image_dir }}/logo.png" alt="pngss" />

But the image is not appearing.

1

There are 1 answers

1
Sami Akkawi On

This is because '%kernel.project_dir%' in image_dir is a folder path, not a url, you will need to define your url there and remove the public part.

Another solution would be to use the symfony/asset library and simply calling {{ asset('images/logos/logo.png') }}