fosUserBundle发送电子邮件注册为空

时间:2013-03-13 22:47:59

标签: email symfony twig fosuserbundle swiftmailer

所以当我在生产环境中通过fosUserBundle表单注册时,它会向我的Gmail发送一封电子邮件但电子邮件中没有确认链接,只有这个

registration.email.message

在电子邮件的标题和正文中,有人知道为什么吗?

2 个答案:

答案 0 :(得分:12)

这是因为电子邮件是使用翻译器获得的内容,而且配置错误。

确保您启用了翻译:

# app/config/config.yml
framework:
    translator: { fallback: %locale% }

# app/config/parameters.yml
parameters:
    locale: en # default locale

此外,如果您使用与英语不同的语言编写应用程序,请确保将密钥registration.email.message翻译成英语。如果不是,您可以通过编写以下文件来覆盖翻译:

# app/Resources/FOSUserBundle/translations/FOSUserBundle.{your_locale}.yml
registration:
    email:
        subject: Registration email subject
        message: |
            Here you can place the content of the email.
            It can be multiline and you even have access to
            variables %username% and %confirmationUrl%.

答案 1 :(得分:0)

这是FOSUser的默认邮件:

{% block subject %}
{% autoescape false %}
{{ 'registration.email.subject'|trans({'%username%': user.username, '%confirmationUrl%': confirmationUrl}, 'FOSUserBundle') }}
{% endautoescape %}
{% endblock %}
{% block body_text %}
{% autoescape false %}
{{ 'registration.email.message'|trans({'%username%': user.username, '%confirmationUrl%': confirmationUrl}, 'FOSUserBundle') }}
{% endautoescape %}
{% endblock %}
{% block body_html %}{% endblock %}

在第8行,'registration.email.message'是电子邮件内容。 trans是替换过滤器。尝试这样的事情:

    {% block subject %}
    {% autoescape false %}
    {{ 'Confirmez votre inscription sur blabla.com'|trans({'%username%': user.username, '%confirmationUrl%': confirmationUrl}, 'FOSUserBundle') }}
    {% endautoescape %}
    {% endblock %}
    {% block body_text %}
    {% autoescape false %}
    {{ 'Bonjour %username%

    Merci de cliquer sur le lien suivant afin de confirmer votre inscription sur blabla.com:

    %confirmationUrl%'|trans({'%username%': user.username, '%confirmationUrl%': confirmationUrl}, 'FOSUserBundle') }}

{% endautoescape %}
{% endblock %}
{% block body_html %}{% endblock %}