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

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

Support

Overriding email to in contact form not working

form plugin plugins

Solved by Thorsten View solution

Started by Thorsten 6 years ago · 4 replies · 889 views
6 years ago

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

6 years ago

@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:

YAML
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: s[email protected]
      from_name: 'Custom sender name'
      to: r[email protected]
      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.

6 years ago

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?

6 years ago

@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.

6 years ago Solution

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

Suggested topics

Topic Participants Replies Views Activity
Support · by Thomas, 1 week ago
2 51 8 hours ago
Support · by Anna, 2 days ago
2 58 10 hours ago
Support · by Justin Young, 11 hours ago
1 30 11 hours ago
Support · by Duc , 1 week ago
2 63 5 days ago
Support · by Colin Hume, 1 week ago
2 55 5 days ago