Skip to content
Grav 2.0 is officially stable. Read the announcement →
Archive

Custom email using the email plugin?

Started by Muut Archive 9 years ago · 11 replies · 2904 views
9 years ago

How do i go about creating a custom email template when using the email plugin? Could anyone point me in the direction of a good guide?

9 years ago

You can see from the docs, that to process email with a custom twig template, you simply need to pass the path of the relevant twig you wish to use. You can use the ones included in the email plugin as good place to start: https://github.com/getgrav/grav-plugin-email

You just need to put these into your Twig template path somewhere. Either in your theme, or in a custom plugin that provides these templates.

9 years ago

Is there an example of one the the forms/default/data.html.twig that i could see, its setting out the content of the email i would like to see really. How would i get data sent into an email?

9 years ago

Thats for building the form is it not? I want to customise the actual email that is sent out.

9 years ago

I think i may have pasted the wrong twig file above? Is not exactly a very user friendly way of creating contact forms, and their respective emails haha :)

9 years ago

I think I misunderstood the question.

You can use the Email plugin to send the result of a form submit, see the example Contact form. In that example, you can set the Twig used by the email to render the data.

That was working with forms to send emails, which is the way you usually interact with that plugin.

If all you want to do is instead customize the overall template layout, and not the content, you can add to your theme the file templates/email/base.html.twig from here https://github.com/getgrav/grav-plugin-email/blob/develop/templates/email/base.html.twig and customize it.

The reason you have to put it in your theme is, you don't need to worry when updating the plugin, your changes will be safe. Of course then the problem is redirected to the theme, this is why you should create your own inherited theme, next thing.

9 years ago

Cheers for that Flavio, so how do i change the layout of the content of the email? I have see that it simply replicates the form layout, so for the contact for it shows, name: email: and message: What would i need to edit to change the layout of that email?

9 years ago

Ok so if you're editing the contact form output, you move this file https://github.com/getgrav/grav-plugin-form/blob/develop/templates/forms/default/data.html.twig in your theme, and customize how the data is rendered. You can all it however you like, and then include that in your form action, where you see

TWIG
        - email:
       subject: "[Site Contact Form] {{ form.value.name|e }}"
       body: "{% include 'forms/data.html.twig' %}"
9 years ago

so to change the layout of the email, i just access the form items using {{ form.value.name|e }} for example? I think i have it now. i will just mess with it and see what i can come up with now :) thanks

9 years ago

I would like to receive emails as html format when someone use the contact form. Is it possible to call an email template file?

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1336 9 years ago
Archive · by Muut Archive, 9 years ago
2 925 9 years ago
Archive · by Muut Archive, 9 years ago
2 4056 9 years ago
Archive · by Muut Archive, 9 years ago
1 2941 9 years ago
Archive · by Muut Archive, 9 years ago
3 1112 9 years ago