Hello,
I’m relatively new to Grav and I’m trying to use multiple contact forms on my new site.
So far everything works fine: the forms are displayed correctly and emails are sent.
What I’m trying to achieve is that every contact form is sending mails to different mail-addresses. So I’m overriding the “to-address” in the process part of my form but this doesn’t work. The mails are always sent to the “to-address” from the email-plugin.
Am I missing something?
Best regards,
Thorsten
@thorsten, According the section Emails sent with Forms in the docs of the email plugin, several properties of an email can be overridden. The to-address
you mention is not one of them, but to
is…
From the docs:
title: Custom form
form:
name: custom_form
fields:
# Any fields you'd like to add to the form:
# Their values may be referenced in email actions via '{{ form.value.FIELDNAME|e }}'
process:
email:
subject: "[Custom form] {{ form.value.name|e }}"
body: "{% include 'forms/data.txt.twig' %}"
from: sender@example.com
from_name: 'Custom sender name'
to: recipient@example.com
to_name: 'Custom recipient name'
content_type: 'text/plain'
process_markdown: true
To test, I copied the form definition from the Example Contact Form and tried the field to
with different addresses. The emails did arrive at the correct mailboxes.
I tried this example too. But it doesn’t work.
Mails are always sent to the default address from the default-configuration.
Can this be a theming-problem?
@thorsten, Easy to find out… Use a fresh install of Grav 1.6.23 + Quark and see what happens…
In my fresh install + Quark the contact form works fine.
So finally I discovered my mistake.
Here is my “lesson learned” if somebody else is having this problem:
After doing a fresh local install the contact form worked fine for me too. So I used this form in my original website but it stopped working again.
I started to change the original form.md file and realized that my changes didn’t have any effect. Maybe it was a caching problem? So I deactivated caching but still the same.
So I started to modify my form.md file piece by piece … still no effect. Until I finally changed the name/id of my contact and then everything worked fine.
Solution: if you have several contact forms on your site be sure to give any form an unique name/id.
1 Like