3

Just as the title indicates, I'm looking for a way to customize the email template of the "click here to activate your account" email that is sent to users when they register. I would also like to know if its possible and how to do this with other system email templates, such as the reset password link email.

Edit: I see you can edit the plain text emails at Settings > Email > Messages however I would like to be able to define a twig template to handle creating HTML versions of these.

3 Answers 3

8

Actually Brad, I was able to figure out a way to do this with some help from @carlcs in the slack channel.

I defined an "HTML Template" in the main email settings screen, then in that template I extend a basic HTML email wrapper, then inside my content block I did this:

{% if emailKey == 'account_activation' %}
    {% include 'mail/activation' %}
{% endif %}
{% if emailKey == 'forgot_password' %}
    {% include 'mail/forgot-password' %}
{% endif %}
{% if emailKey == 'test_email' %}
    {% include 'mail/test-email' %}
{% endif %}
{% if emailKey == 'verify_new_email' %}
    {% include 'mail/verify-new-email' %}
{% endif %}

Then I just created HTML versions of each email within the context of my wrapper.

It works perfectly!

3
  • 1
    Ahh... clever!!
    – Brad Bell
    Oct 19, 2017 at 16:43
  • Hi Rick, could you explain a little bit more what you did? Where is the main email settings screen (Utilities / System messages ?) Thanks. Feb 7, 2020 at 10:57
  • 1
    @migswd Sorry for the delay. I believe this post was originally made based on Craft2, not Craft3. I don't think there is a spot for that setting in craft3 anymore. Mar 9, 2020 at 18:02
3

With @sublymerick's answer as inspiration I define a default html template, _emails/index.twig, passing in the message content that is defined in Craft admin to an html wrapper rather than create separate templates for each.

{% if emailKey is defined and emailKey in [
    'account_activation', 
    'forgot_password', 
    'test_email', 
    'verify_new_email'] 
%}    
    {% include '_emails/templates/basic' with {
        body: body | raw,
    } only %}
{% endif %}
3
  • Hi Seth. Could you explain a little bit more what you did? What do you have in _emails/templates/basic ? Thanks. Feb 7, 2020 at 11:04
  • _emails/templates/basic is the markup (tables, urgh!) for the email body. So rather than maintaining seperate templates for each message I'd code up the email with everything required (logo, header, footer links, etc) then just pass the message body into that. Feb 7, 2020 at 15:39
  • Great thank you ! :) Feb 8, 2020 at 9:12
1

I see you can edit the plain text emails at Settings > Email > Messages however I would like to be able to define a twig template to handle creating HTML versions of these.

Currently not possible natively, but there is a feature request you might want to add a thumbs-up/comment to:

https://github.com/craftcms/cms/issues/1020

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.