Sends an email to the email address defined in the endpoint field.
Or dynamically:
{%- apply spaceless -%}
{%- set destination = "[email protected]" -%}
{%- if data.my_destination_field is same as("my_destination_value") -%}
{%- set destination = "[email protected]" -%}
{%- endif -%}
{%- endapply -%}
{{- destination -}}
Email sender, subject, and body are defined in the message field using the "from", "subject", and "body" keys respectively. The output should be a json object.
{% autoescape %}
{% set email = {
"from": "[email protected]",
"subject": "Form submission from website",
"body": "foobar"
} %}
{% endautoescape %}
{{ email|json_encode|raw }}
The message can access the filled in data of the form, for example submitted fields "email", "name", "firstname". Use the following approach if you want to include newlines in your email body.
{% autoescape %}
{% set body %}
Email {{ data.email }}
Name {{ data.name }}
Firstname {{ data.firstname }}
{% endset %}
{% set email = {
"from": data.email,
"subject": "Email Form subject",
"body": body
} %}
{% endautoescape %}
{{ email|json_encode|raw }}
If your body contains HTML structured text, you have to pass the content-type option text/html in the email object. By default text/plain is used.
{% autoescape %}
{% set body %}
Email {{ data.email }}
Name {{ data.name }}
Firstname {{ data.firstname }}
{% endset %}
{% set email = {
"from": data.email,
"subject": "Email Form subject",
"body": body,
"content-type": "text/html"
} %}
{% endautoescape %}
{{ email|json_encode|raw }}
You can also define a reply-to
option:
{% autoescape %}
{% set body %}
Email {{ data.email }}
Name {{ data.name }}
Firstname {{ data.firstname }}
{% endset %}
{% set email = {
"from": "[email protected]",
"reply-to": data.email,
"subject": "Email Form subject",
"body": body
} %}
{% endautoescape %}
{{ email|js
Use the formData helper object to retrieve all files that are attached to the form submission.
You can override the default values for each file using the map
filter as shown below.
{% autoescape %}
{% set body %}
Email {{ data.email }}
Name {{ data.name }}
Firstname {{ data.firstname }}
{% endset %}
{% set email = {
"from": data.email,
"subject": "Email Form subject",
"body": body,
"attachments": formData.allFiles|map(v => v.toArray)|map(f => {
filename: f.originalName|ems_webalize,
mimeType: f.mimeType,
pathname: f.pathname,
})
} %}
{% endautoescape %}
{{ email|json_encode|raw }}