I am trying to define my own template for e-mail that is sent when user request for password, but it does not work when adding HTML part.
This is the template:
{% trans_default_domain 'FOSUserBundle' %}
{% block subject %}
{% autoescape false %}
{{ 'resetting.email.subject'|trans({'%username%': user.username, '%confirmationUrl%': confirmationUrl}) }}
{% endautoescape %}
{% endblock %}
{% block body_text %}
{% autoescape false %}
{{ 'resetting.email.message'|trans({'%username%': user.username, '%confirmationUrl%': confirmationUrl}) }}
{% endautoescape %}
{% endblock %}
{% block body_html %}
{% autoescape false %}
<div dir="ltr" style="display: block; width: 100%; background: #ffffff">
<table style='width: 100%; border: none'>
<tr style='height: 20px; background-color: #5A82FF'>
<td></td>
</tr>
<tr>
<td style="padding: 30px 0; font-family: Verdana">
{{ 'resetting.email.message_html'|trans({'%username%': user.username, '%confirmationUrl%': confirmationUrl}) }}
</td>
</tr>
<tr style='height: 20px; background-color: #4ED53E'>
<td></td>
</tr>
</table>
</div>
{% endautoescape %}
{% endblock %}
When the password request is sent, the mail is received in text format with both parts embedded in it, this way:
Estimado [email protected]!
Para restablecer tu contraseña - por favor visita http://xxx.xxx.xxx.xxx
Atte,
El equipo de XXX
<div dir="ltr" style="display: block; width: 100%; background: #ffffff">
<table style='width: 100%; border: none'>
<tr style='height: 20px; background-color: #5A82FF'>
<td></td>
</tr>
<tr>
<td style="padding: 30px 0; font-family: Verdana">
Estimado [email protected]!
<br /><br />
Para restablecer tu contraseña - por favor visita http://xxx.xxx.xxx.xxx
<br /><br />
Atte,<br />
El equipo de XXX
</td>
</tr>
<tr style='height: 20px; background-color: #4ED53E'>
<td></td>
</tr>
</table>
</div>
What may be wrong?
Thanks Jaime
I ran into a similar problem.
The default mailer only supports sending plain text messages. If you want to send multipart messages, the easiest solution is to use the TwigSwiftMailer implementation instead. It expects your twig template to define 3 blocks:
subject
containing the email subjectbody_text
rendering the plain text version of the messagebody_html
rendering the html mailYou must set the service in the config (e.g. app/config/config.yml)
fos_user:
# ...
service:
mailer: fos_user.mailer.twig_swift
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With