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.

Plugins

Configuring email address

Solved by elisabetta View solution

Started by elisabetta 6 years ago · 6 replies · 1291 views
6 years ago

How can we configure the email plugin so that the person that filled out the form is set as reply_to? At present the fields "email from" and "email to" in plugin set up are the same (let us say: [email protected]), but this way the sender looks the same as the receiver and I can't use the "reply" option.
I found this chunk of code:

TWIG
process:
  - email:
      from: "{{ form.value.email }}"
      to: "{{ config.plugins.email.to 1 }}"
      reply_to: "{{ form.value.email }}"
      subject: "Contact by {{ form.value.name|e }}"
      body: "{% include ‘forms/data.html.twig’ %}"

My contact form (the same as the the "simple form" of GRAV documentation) includes also the google captcha, but if I include the code above in my contact.md file, the captcha are no longer working...
Can someone provide me with a corrected code?
Thanks a lot!

last edited 02/08/20 by pamtbaau
6 years ago

@maria, It looks like this post contains two separate questions. 1. Configuring the Email plugin and 2. Google captcha not working in your form.

If so, would you mind opening a second post for the captcha question?

6 years ago

two questions which are actually overlapping each other: if I configure my contact.md file adding the code, the google captcha are not working properly. Probably is my fault, because at present the "captcha: true" condition is immediately after "process:" and I don't know if the chunk of code email:

TWIG
from: "{{ form.value.email }}"
to: "{{ config.plugins.email.to 1 }}"
reply_to: "{{ form.value.email }}"
subject: "Contact by {{ form.value.name|e }}"
body: "{% include ‘forms/data.html.twig’ %}"

must be included before or after the "captcha: true" code.

last edited 02/08/20 by pamtbaau
6 years ago

What is the 1 good for in this line ?

@maria:
to: "{{ config.plugins.email.to 1 }}"

6 years ago

Sorry! the 1 is a mistake! Correct is to: "{{ config.plugins.email.to }}"

6 years ago

Here my contact.md file:

YAML
---

title: 'Contact Form'
form:
    name: contact
    fields:
        name:
            label: Name
            placeholder: 'Enter your name'
            autocomplete: 'on'
            type: text
            validate:
                required: true
        email:
            label: Email
            placeholder: 'Enter your email address'
            type: email
            validate:
                required: true
        message:
            label: Message
            placeholder: 'Enter your message'
            type: textarea
            validate:
                required: true
        g-recaptcha-response:
            label: Captcha
            type: captcha
            recaptcha_not_validated: 'Captcha not valid!'
    buttons:
        submit:
            type: submit
            value: Submit
        reset:
            type: reset
            value: Reset
    process:
        captcha: true
        save:
            fileprefix: contact-
            dateformat: Ymd-His-u
            extension: txt
            body: '{% include ''forms/data.txt.twig'' %}'
        email:
            subject: '[Site Contact Form] {{ form.value.name|e }}'
            body: '{% include ''forms/data.html.twig'' %}'
        message: 'Thank you for getting in touch!'
        display: thankyou
---

I wonder where I can paste the chunk of code I wrote in my first post...I suppose immediately after process: but if I do this , the captcha are not correctly processed
Any help would be appreciated!!

last edited 02/10/20 by elisabetta
6 years ago Solution

Ok! After a lot of tries this is the code which works correctly. Please note I use Helium and Gantry 5 for GRAV- I'm not sure if this code is suitable for other Grav themes.

YAML
title:  'Contact Form'

form:
  fields:
    name:
      type: text
      label: Name
      validate:
        required: true
        message: Please enter your name!
    email:
      type: text
      label: Email
      validate:
        type: email
        required: true
        message: Please enter your email address!
    subject:
      type: text
      label: Subject
      validate:
        required: true
        message: Please enter a subject for your message!
    message:
      type: textarea
      label: Message
      validate:
        required: true
        min: 10
        message: Email message needs to be more than 10 characters long!
      g-recaptcha-response:
              type: captcha
              label: Captcha
              validate:
                required: true
              recaptcha_not_validated: 'Captcha not valid!'

  buttons:
    submit:
      type: submit
      value: Send Email

  process:
    captcha: true
    email:
      from: "{{ form.value.email }}"
      to: "{{ config.plugins.email.to }}"
      subject: "[Contact] {{ form.value.subject|raw }}"
      body: "{{ form.value.message }}<br /><br />{{ form.value.name }}<br />{{ form.value.email }}"
    message: 'Thank you from contacting us!'
    display: thankyou

👍 2
last edited 02/11/20 by elisabetta

Suggested topics

Topic Participants Replies Views Activity
Plugins · by Rene, 1 week ago
2 42 1 week ago
Plugins · by Xavier, 4 weeks ago
2 53 4 weeks ago
Plugins · by Luka Prinčič, 7 years ago
3 1179 1 month ago
Plugins · by Sebastian van de Meer, 1 month ago
1 47 1 month ago
Plugins · by PIERROT Alain, 2 months ago
3 71 2 months ago