Reputation: 19
I work with symfony i try to send mails with Mailer,
{% block body %}
{% apply inky_to_html|inline_css(source('@css/foundation-emails.css')) %}
<container>
<row>
<columns>
<h1 class="text-center">Rénisialisation de mot de passe</h1>
<p class="text-center">{{ sujet }}</p>
{# <p class="text-center">Cliquer sur le lien ci-dessu pour voir les détails</p>#}
</columns>
</row>
<spacer size="16"></spacer>
<row>
<columns>
<center>
<button class="rounded large" href="https://localhost:8000/user/reset/{{ id }}/{{ reset_token }}">Rénitialiser</button>
</center>
</columns>
</row>
</container>
<img src="{{ email.image('@images/logo.png') }}" alt="Logo" style="width: 260px">
{% endapply %}
{% endblock %}
The email template work but i have some templates with a lot of images and those images is showed as attachement in the end of email. i want to show juste my template without this attachement
Upvotes: 0
Views: 71
Reputation: 233
There are two ways to have rich emails with images. One where you actually send the image embedded in the email message and the other is simply to provide a link to grab the image from the internet. Both methods have their benefits and drawbacks.
Embedded images will almost always show up in a clients email client - because they are already downloaded. The downside is that it makes the emails themselves larger and some clients will show the image as an attachment. Some email clients hide the attachment when it sees that it is used in the message body. But you have no control over this when embedding images.
Linked images will only sometimes be shown by a client's email client -- they are far more likely to see your images in the email when they're embedded. The upside to this method is that the emails are smaller.
If you want to go the Linked Image Route, simply use
<img src="https://example.com/path-to-image" alt="Logo">
or if you're using assets (https://symfony.com/doc/current/components/asset.html)
<image src="{{ absolute_url(asset('images/logo.png') }}" alt="Logo">
Otherwise, for embedded image help It appears that you already know how to embed the image, but if this isn't working, then you might need to check out your config file.
# config/packages/twig.yaml
twig:
paths:
# point this wherever your images live
'%kernel.project_dir%/assets/images': images
Full details from the documentation is at: https://symfony.com/doc/6.4/mailer.html#embedding-images-1
Upvotes: 0