Skip to content
● Meet Grav Guard: keep every Grav site you run secure and up to date, all from one place. Free for up to 3 sites. Read more →

Issue using form with email plugin

form plugins

Started by Alberto 2 years ago · 1 replies · 1271 views
2 years ago

Hi there!

I'm trying to build a contact form and though i tried to follow docs, it seems I'm still missing something.
On my server I have postfix installed with all the needed certificates to send emails.
If i run this command sudo bin/plugin email test-email -t <my-email> I receive it.
But if I fill the grav form and submit, it seems the service doesn't even get called.

This is my email plugin configuration:

YAML
enabled: true
from: <my-domain>
to: <my-email>
mailer:
  engine: smtp
  smtp:
server: <my-server-ip>
    port: 25
    encryption: none
    user: null
    password: null
  sendmail:
    bin: "/usr/sbin/sendmail -bs"
content_type: text/html
debug: true
cc: null
bcc: null
reply_to: null
body: null

and this is my contact form frontmatter

YAML
---
title: Contact us
cache_enable: false
description: Feel free to reach out! We’ll get back to you as soon as possible.
template: partials/components/form-contact-us
process:
  twig: true
  markdown: false

form:
  action: /contacts
  name: contact_form

  fields:
    - name: name
      label: Name
      type: text
      placeholder: Enter your name
      validate:
        required: true

    - name: surname
      label: Surname
      type: text
      placeholder: Enter your surname
      validate:
        required: true

    - name: email
      label: Email
      type: email
      placeholder: Enter your email
      validate:
        required: true

    - name: message
      label: Message
      type: textarea
      placeholder: Enter your message
      validate:
        required: true
        min: 10

  buttons:
    - type: submit
      value: Send

  process:
    email:
      - from: "{{ config.plugins.email.from }}"
        to: "{{ config.plugins.email.to }}"
        subject: "New Message from {{ form.value.name|e }} {{ form.value.surname|e }}"
        body: |
          Hi,
          You have received a new message.

          **Name:** {{ form.value.name|e }}
          **Surname:** {{ form.value.surname|e }}
          **Email:** {{ form.value.email|e }}
          **Message:**
          {{ form.value.message }}

    message: "Thank you for getting in touch!"
    reset: true
---
and here is the twig template \user\themes\quark\templates\partials\components\form-contact-us.html.twig

type or paste code here

TWIG
<section class="form-contact-us-wrapper">
    <div class="form-contact-us">
        <div class="header">
            <h3>{{ module.header.title }}</h3>
            <span>{{ module.header.description }}</span>
        </div>
        <form method="post" action="{{ page.url }}">
            <ul class="controls">
                <li class="control">
                    <label for="name">{{ "NAME"|t }}</label>
                    <input type="text" id="name" name="name" placeholder="{{ "ENTER_YOUR_NAME"|t }}" required>
                </li>
                <li class="control">
                    <label for="surname">{{ "SURNAME"|t }}</label>
                    <input type="text" id="surname" name="surname" placeholder="{{ "ENTER_YOUR_SURNAME"|t }}" required>
                </li>
                <li class="control">
                    <label for="email">{{ "EMAIL"|t }}</label>
                    <input type="email" id="email" name="email" placeholder="{{ "ENTER_YOUR_EMAIL_ADDRESS"|t }}" required>
                </li>
                <li class="control">
                    <label for="message">{{ "MESSAGE"|t }}</label>
                    <textarea id="message" name="message" placeholder="{{ "ENTER_YOUR_MESSAGE"|t }}" required minlength="10"></textarea>
                </li>
            </ul>

            <button type="submit" title="{{ "SEND"|t }}">{{ "SEND"|t }}</button>
        </form>
    </div>
</section>

2 years ago

@bebiuz, You should not create a custom template. The Form plugin will take care of it. The email process action defined in the form definition will redirect data from the form to the Email plugin.

Suggested topics

Topic Participants Replies Views Activity
Plugins · by DrPen, 4 weeks ago
2 314 3 weeks ago
Plugins · by renedebaaij, 1 month ago
1 278 4 weeks ago
Plugins · by Thomas, 4 weeks ago
1 293 4 weeks ago
Plugins · by complanar, 2 months ago
6 614 1 month ago
Plugins · by BenLaKnet, 2 months ago
1 525 2 months ago