Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FOSUserBundle resetting e-mail HTML template does not work

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

like image 882
jstuardo Avatar asked Dec 21 '13 15:12

jstuardo


1 Answers

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 subject
  • body_text rendering the plain text version of the message
  • body_html rendering the html mail

You must set the service in the config (e.g. app/config/config.yml)

fos_user:
    # ...
    service:
        mailer: fos_user.mailer.twig_swift
like image 133
hasentopf Avatar answered Nov 07 '22 16:11

hasentopf