Configuring email address

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: info@mysite.com), 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:

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!

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

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:

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.

What is the 1 good for in this line ?

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

Here my contact.md file:

---

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!!

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.

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 Likes