Send a confirmation email with FormIt

on 19-Sep-2010 | Comments ( 12 ) Tags: Revolution
Seems that the 1.3.0 version and above has this functionality built in(see the AutoResponder hook). You can still use this tutorial as a guide to your custom hooks.

As example we will be using a simple contact form that holds 4 fields: name, email, subject and message. On submit FormIt will send 2 different emails, one to you and one to the user.

In order to send a confirmation email with FormIt, we'll need to create a new chunk and a new snippet. The chunk will be the template of the confirmation email and the snippet will make use of this template, replace any placeholders and send the email to the user.

The FormIt call and the Form

    &emailSubject=`CONTACT FORM: [[+subject]]`

<div class="error">[[+fi.error.error_message]]</div>

<form action="[[~[[*id]]]]" method="post" class="form">
    <input type="hidden" name="nospam:blank" value="" />

    <div class="formRow">
        <label for="name">Name: </label>
        <input type="text" name="name:required" id="name" value="[[]]" />
        <span class="error">[[]]</span>
    <div class="formRow">
        <label for="name">Email: </label>
        <input type="text" name="email:email:required" id="email" value="[[]]" />
        <span class="error">[[]]</span>

    <div class="formRow">
        <label for="subject">Subject: </label>
        <input type="text" name="subject:required:stripTags" id="subject" value="[[+fi.subject]]" />
        <span class="error">[[+fi.error.subject]]</span>
    <div class="formRow">
        <label for="message">Message: </label><span class="error">[[+fi.error.message]]</span> <br/>
        <textarea name="message:required:stripTags" id="message" cols="55" rows="7">[[+fi.message]]</textarea>
    <div class="formRowSubmit">
        <input type="submit" value="Send" name="Submit"/>

The code above has 2 parts. The FormIt call and the html for the form. The only thing that you need to pay attention is the extra hook present in the FormIt call: emailUser. This is also the name of the snippet that will take the confirmation email, parse it and send it to the user.

The Contact Template

Please create a new chunk named ContactTpl and paste the code below:

This is the message [[+name]] ([[+email]]) sent from the Contact Form:

The Confirmation Template

Please create a new chunk named ConfirmationTpl and paste the code below:

  Hi [[+name]],<br/>
  We received your message and we will get back to you as soon as possible.

  Here is your message:<br/>

The emailUser snippet

This is the code that sends the confirmation email. Please create a new snippet named emailUser and paste the code below: 

$mailFrom = $modx->getOption('emailsender'); //OR USE YOUR OWN;
$mailFromName = $modx->getOption('site_name'); //OR USE YOUR OWN;
$mailSender = $modx->getOption('site_name'); //OR USE YOUR OWN;
$mailSubject = 'YOUR SUBJECT';
$mailReplyTo = $mailFrom;

//get fields values so they can be replaced in the email chunk
$confirmationFields['message'] = $scriptProperties['fields']['message'];
$confirmationFields['name'] = $scriptProperties['fields']['name'];

//get user's email
$mailTo= $scriptProperties['fields']['email'];
$message = $modx->getChunk('ConfirmationTpl', $confirmationFields);
$modx->getService('mail', 'mail.modPHPMailer');

if (!$modx->mail->send()) {
    $modx->log(modX::LOG_LEVEL_ERROR,'An error occurred while trying to send the email: '.$err);
return false;


return true;

There are things that you might want to do to this snippet:

Hopefully this makes sens. Let me know your opinion in the comments section.

Write a comment

  • Required fields are marked with *.

If you have trouble reading the code, click on the code itself to generate a new random code.
Posts: 10
Not working
Reply #12 on : Wed September 29, 2010, 05:00:51
Hi mate,

I having just been trying out your code and I'm having a bit of trouble getting it to work. I'm using modx revolution.

Do you know of any thing that might stop it working? Should my hosting be setup in a particular way in for mail to be sent? etc...

Any help would be appreciated.


Posts: 2
Re: Send a confirmation email with FormIt
Reply #11 on : Wed September 29, 2010, 07:43:21
There are some discussions going on here:,53795.0/topicseen.html

See Bob's reply: MODx will use SMTP on it's own whenever a snippet sends mail if you set the SMTP System Settings. If you set those, don't use the snippet's SMTP parameters (if any)
ajay kumar
Posts: 10
Reply #10 on : Sun December 05, 2010, 10:53:34
i want confirm my orkut account for downloding items, iwant to send confirm msg.
Posts: 10
Reply #9 on : Wed December 22, 2010, 01:37:21
Nice and clear tutotorial!
It helps me!

How I used it you can see on that page:

Thanx one more and more time! =)
Posts: 10
Reply #8 on : Tue August 30, 2011, 03:00:13
Posts: 10
It worked!
Reply #7 on : Wed November 09, 2011, 16:36:39
But it slowed down my entire site and admin, so I uninstalled FormIt and my site is back to regular speeds. Odd.
Posts: 10
Re: Send a confirmation email with FormIt
Reply #6 on : Fri January 27, 2012, 06:22:45

I am new in Modx Revo

Mine Validation is working, but form is not sending any emails to email id or not even success message.

Posts: 10
adding a second email
Reply #5 on : Thu March 29, 2012, 09:28:09
Is there a way to add a second email address to the send list? and if so, is there a way to send a different set of content to it? Like an email goes out to the site mod giving him information and then and email goes out to the visitor giving them confirmation.
Posts: 10
redirect not working anymore
Reply #4 on : Sun July 13, 2014, 14:58:53
Hi there!

I'm using this modification/extra snipper "emailUser" in my FormIt. But by using this "custom hook" the form doesn't redirect anymore on succeddful validation.

What to do?
Posts: 2
Re: Send a confirmation email with FormIt
Reply #3 on : Sun July 13, 2014, 16:18:58
This was build for one of the first versions of FormIt. Maybe they changed the way it works. Anyway the new versions should have the autoresponder hook available
Posts: 10
Reply #2 on : Wed October 22, 2014, 02:58:52
how to use formit extra in modx revo.
Posts: 10
Re: Send a confirmation email with FormIt
Reply #1 on : Thu April 20, 2017, 07:17:59

Quick modx Evolution Tags

  • cached [[snippet]] or uncached [!snippet!]
  • {{chunk}}
  • [+placeholder+]
  • [*resourceField/TV*]
  • [^timing^]
  • [~link~]

Quick modx Revolution Tags

  • [[snippet]]
  • [[$chunk]]
  • [[+placeholder]]
  • [[*resourceField/TV]]
  • [[~link]]
  • [^timing^]
  • [[++systemSetting]]
  • [[%languageStringKey]]
  • all tags can be called un-cached like: [[! snippet]]

Timing Tags (Evo and Revo)

  • [^qt^] - Query time
  • [^q^] - Query count
  • [^p^] - Parse time
  • [^t^] - Total time
  • [^s^] - Source
© modxRULES! 2009-2014