How can single form send two emails using different titles and bodies


#1

I’m trying to figure out how to specify the output of a form.
The standard output is enough for the configured emailaddress, but for the form-email i want a different format with output. How do i do this?

        - email:
            from: "{{ config.plugins.email.from }}"
            to:
              - "{{ config.plugins.email.from }}"
              - "{{ form.value.email }}"
            subject: "[Aanmeldformulier] {{ form.value.name|e }}"
            body: "{% include 'forms/data.html.twig' %}"```

I need to figure out how to specify a second body/subject for {{ form.value.email }}.

#2

I have setup my email form to display a simple html format in the email within the body. What you need to do is change this line from:

body: "{% include 'forms/data.html.twig' %}" 

to:

body: "{% extends 'email/base.html.twig' %}"
  • In your theme templates folder, create an ‘email’ folder inside templates/
  • Download this html email template and upload the base.html.twig to the email folder.
  • Test the template by filling out the contact form. You should receive a customize message containing the contact’s info. Verify and tweak however you want the body of the email to read.

#3

Thanks but this is not what i am looking for… any other suggestions?


#4

@SjoerdSmeets It might be worth considering to rephrase the question and explaining what you do look for… :wink:

After some pondering… Do you perhaps mean that you want to send two different emails, each with its own to/subject/body? One to yourself and one to {{ form.value.email }}?

I have no hands-on experience with the Email plugin, but have you tried splitting the email action into two separate actions? One to yourself and one to the client each with their own to/subject/body?


#5

That’s exactly what i want!


#6

@SjoerdSmeets And? Have your tried the suggestion of sending two different ‘email’ actions?


#7

I’m still looking for an example howto do this… haven’t found it yet…


#8

@SjoerdSmeets With some help of the Form docs, albeit a bit hidden I have to admit… The following seems to be doing what you are looking for.

Note: I used a fresh install of Grav 1.6.0-beta.6 with Quark and an inherited theme.

  • Create a new page with a contact form:
    user/pages/03.contact/
       form.md
    
  • Add the following frontmatter with two separate email actions:
    ---
    title: Contact Form
    
    form:
        name: contact
    
        fields:
            - name: name
              label: Name
              placeholder: Enter your name
              autocomplete: on
              type: text
              validate:
                required: true
    
            - name: email
              label: Email
              placeholder: Enter your email address
              type: email
              validate:
                required: true
    
            - name: message
              label: Message
              placeholder: Enter your message
              type: textarea
              validate:
                required: true
    
        buttons:
            - type: submit
              value: Submit
            - type: reset
              value: Reset
    
        process:
            - email:
                # To myself
                to: "{{ config.plugins.email.to }}"
                subject: "Email to myself"
            - email:
                # To visitor
                # Using defaults for 'to' and 'from'
                subject: "Email to visitor"
                body: "{% include 'forms/visitor.html.twig' %}"  <-- a custom template
    ---
    
    # Contact form
    
    Some sample page content
    
  • In your inherited theme create a new Twig template ‘users/themes/mytheme/templates/forms/visitor.html.twig’. Add the following content:
    <p>This is the body for the visitor's email based on template "forms/data.html.twig"
    which can be found in folder "/user/plugins/form/templates/forms/".</p>;
    
    {% include "forms/data.html.twig" %} 
    

Hope this helps...

#9

That’s it, thank you very much!


#10

@SjoerdSmeets Nice!

I have taken the liberty to change the title of your post to match your intention a tad better.