Skip to main content

Mail to form user

Sending confirmation emails to form users is a great way to provide them with a copy of their submission and enhance communication. This guide will show you how to set up user-related fields and create the necessary email templates to send personalized responses.

To send a confirmation email, you’ll need to define specific fields in your blueprint and add a template for the email content. Follow these steps to set it up seamlessly.

User-Related Fields

To send an email to the form user, you’ll need the following fields in your blueprint:

  1. Email Field:Add a field with type: email and the attribute reply: true. This tells the plugin to use the value entered here as the recipient for the reply email.
  2. Optional Name Field:To personalize the email, include a text field for the user’s name with the attribute username: true.
fields:
  name:
    type: text
    label: Name
    placeholder: Your name
    required: true
    username: true
  email:
    type: email
    label: Email
    placeholder: Your Email
    required: true
    reply: true
    replyto: true

Templates

Next, create a reply.text.php file in your template folder. This file will define the content of the email sent to the form user.

Learn more about the file structure here.

Hello <?= $form->name() ?>,

thanks for your email. We will get back to you soon.

Here is the information provided by you:

<?php foreach ($form->toArray() as $field): ?>
    <?= $field->key() . ': ' . $field->value() . "\n\n" ?>
<?php endforeach; ?>

Have a great day.

<?php if($email->footer()->isNotEmpty()): ?>
---
<?= $email->footer() ?>
<?php endif; ?>

With these steps, your form will automatically send confirmation emails to the user, including their submitted data. This improves user experience and ensures they have a copy for their records. Want to customize further? Add an HTML template (reply.html.php) for richer formatting.