How to Send Confirmation Emails to Form Submitters in Mura CMS

A question came up in the Mura CMS forums about "sending a confirmation message automatically" that I thought other developers and/or users of Mura CMS might find helpful.

When you create a form in Mura CMS, there are a couple of convenient fields available. One field allows for a comma-separated list of email addresses to receive notification whenever the form is submitted. Another field is a text area for displaying a "confirmation message" to the person who submits the form.

One field that isn't currently available is a checkbox to "send copy to submitter." A good reason for this could simply be that since a form could contain any number of unique fields and field names, it could be very difficult to programmatically allow for something as unique as this.

So I wrote a simple custom display object that will essentially check for a form field called "email" and if it is valid, send a confirmation message to the submitter (assuming the submitter's email is contained within the "email" form field). Lost yet? I hope not.

First, you'll want to create a custom display object. you can copy the code below and save it to/as "[siteid]/includes/display_objects/custom/dsp_email_confirmation.cfm"


<cfsilent>
<!---

    Document:        dsp_email_confirmation.cfm
    Version:        20091005.01
    Author:            Steve Withington | www.stephenwithington.com
    
    Purpose:        I send email confirmations to form submitters.
    
    Instructions:    Assuming you've placed this file in/as:
                    "[siteid]/includes/display_objects/custom/dsp_email_confirmation.cfm"
                    
                    Go to "Forms" in your admin, select the form you want to use this script
                    in, go to the "Confirmation Message" text area, then copy + paste this:
                    
                    [mura]dspInclude('display_objects/custom/dsp_confirmation_email.cfm')[/mura]
                    
                    This could be the only line of text in your Confirmation Message text area
                    since now you can modify the confirmation text below. However, any
                    text in the "Confirmation Message" form field will also be display on
                    the screen.
                    
                    The confirmationText below can even be a dynamic field that's passed in
                    on form submission, etc.

--->

<cfsavecontent variable="confirmationText">
<cfoutput>Thank you for for your inquiry. A representative will contact you shortly. For immediate assistance, feel free to call 800.555.1212.</cfoutput>
</cfsavecontent>
</cfsilent>
<cfoutput><p class="success">#confirmationText#</p></cfoutput>
<cfif structKeyExists(request, "email") and isValid("email", request.email)>
    <cfsilent>
        <cfset site = application.settingsManager.getSite(request.siteID) />
        <cfset success=true />
        <cftry>
            <cfset email=application.serviceFactory.getBean('mailer') />
            <cfset email.sendText(confirmationText, form.email, form.email, site.getSite(), request.siteid, form.email) />
            <cfcatch>
                <cfset success=false />
            </cfcatch>
        </cftry>
    </cfsilent>
    <cfoutput>
        <cfif success>
            <!--- if successful, a confirmation message can be displayed here --->
            <p class="success"><em>A confirmation has also been sent to your email.</em></p>
            <cfelse>
            <!--- if an error occurs, an error message can be displayed here --->
            <p class="error">Sorry, we experienced a problem in our attempt to send you a confirmation via email.</p>
        </cfif>
    </cfoutput>
    <cfelse>
    <!--- you can display an error message if the email address provided is not valid --->
    <p class="error">Unfortunately, the email address you provided was not a valid email address.</p>
</cfif>

Next, you'll want to go to your "Forms" section in your admin area, select the form you want to use this script in, go to the "Confirmation Message" text area, then copy and past this in:


[mura]dspInclude('display_objects/custom/dsp_email_confirmation.cfm')[/mura]

You can then simply modify the confirmation message within the script, or even pass one in dynamically.

Hope this helps!

Comments
Thanks a bunch for sharing! :-)
# Posted By Jonas | 1/11/10 11:14 AM
Hey Steve. Thanks for sharing. I am using this on my work site and does as advertised

I did note a minor error in the notes and in the mura tag.

One says

dsp_email_confirmation.cfm

and one says

dsp_confirmation_email.cfm

easy enough fix but generated an error before I figured out why so thought I'd mention it.
# Posted By Burt Abreu | 4/2/10 12:16 PM
@Burt, nice catch! i fixed the post, thanks.
# Posted By Steve Withington | 4/2/10 1:34 PM
Steve,

How would I set this out to send out the confirmation with graphics and images as opposed to a text email?
# Posted By Joel | 12/3/10 11:18 PM
@Joel,

It really wouldn't be all that much different. You could create a variable called 'confirmationHTML' which could essentially be a cfsavecontent of an external html or cfm file and then instead of

email.sendText(confirmationText, form.email, form.email, site.getSite(), request.siteid, form.email)

you could use something like:

email.sendHTML(confirmationHTML, form.email, form.email, site.getSite(), request.siteid, form.email)

Good luck!
# Posted By Steve Withington | 12/7/10 12:24 PM
Steve, nice post. Was looking for this exact thing.

Does this method still send an email to the administrator of the website? So in essence does it send 2 emails out... one to the submitter and the other to the admin?
# Posted By jbuda | 3/2/11 6:40 AM
@jbuda,

yes, mura will also send emails to the email address (or list of email addresses), if any, that have been entered in the 'Send data to emal address' field when the form was created/edited.
# Posted By Steve Withington | 3/2/11 7:54 AM
It may be worth noting that this won't work if the redirect_url is specified in the form.... as i just found out! Could not work out why the submitter was not getting anything but the admin address as.

May need to update your snippet slightly and add in a redirect there. Need to allow the CMS user to update the content of the confirmation page.

Very helpful post though.
# Posted By jbuda | 3/2/11 8:00 AM
@jbuda,

fyi, there's a field called 'Confirmation Message' that CMS users can edit for exactly that reason.
# Posted By Steve Withington | 3/2/11 8:19 AM
But then i would not have been able to put the [mura]dspInclude('display_objects/custom/forms/dsp_email_confirmations.cfm')[/mura] into the message box?

Unless i can use the above snippet, as well as a success message underneath? Intereesting.

Thanks again
# Posted By jbuda | 3/2/11 8:25 AM
@jbuda,

correct, you can use both ... so something like:

<p>Thank you! A representative will contact you within the next 24/hours. If you need immediate assistance, please call 800.555.1212</p>
[mura]dspInclude('display_objects/custom/forms/dsp_email_confirmations.cfm')[/mura]
# Posted By Steve Withington | 3/2/11 9:11 AM
Hey Steve,

Thanks for this post! The method works great.

My only question is in regards to the HTML confirmation email. I setup a test HTML file and set that to email to the user, but the email that gets delivered actually has all of the HTML in the body...it's not rendering the tags.

Any advice?

Thanks!
# Posted By Ronnie | 1/11/12 12:18 PM
Nevermind my previous comment... I had missed changing email.sendText to email.sendHTML

Works great now! Thanks Steve!
# Posted By Ronnie | 1/11/12 12:31 PM
Thank you for this information. I'm new to Mura and want to do something very similar. Perhaps you can help me figure out how?
I'd simply like to override the email address entered into the "Send data to email address" field of the edit form screen, based on a selected field of the form.
so if MyField = Y send to abc@xyz.com
if MyField = Z send to xyz@abc.com

that's it.

Thanks you, any help is appreciated!
# Posted By Rich | 6/21/12 4:50 PM
Is there a way that I can make it so the Confirmation e-mail is sent from a specific e-mail? Right now, it "sends" the e-mail from the submitter's address, how can I change this?

Thanks!
# Posted By Susan | 8/10/16 10:24 AM
This is so easy to do, man. I can't believe that I didn't know this before at my essay writing job. It would have made my job so much easier and that would be so good for me.
# Posted By best essays | 3/15/18 8:41 AM
Light and breathable, naturally http://www.cirohair.co.uk formed, stylish and elegant, hand-crocheted https://www.extensionofbeauty.co.uk top-spinning, one mesh is realistic and breathable, natural https://www.wigsandclips.co.uk texture, perfect shape, the unprecedented maximum discount, what are the http://www.humanhair-extensions.co.uk mothers waiting for?
# Posted By cheap hair extensions | 8/30/18 2:46 AM
Cool work done here! I appreciate you for sharing great content with us. I will use this in my https://de.altoconvertwordtopdf.com/faq paper, and my readers will be pleased with my work. You always help me, and for that, I thank you.
# Posted By james | 9/8/19 2:03 PM
Now that I know how to send confirmation emails to form submitters working at http://mobiilikasinoelama.hatenablog.com/entry/201..., I'll send them these emails now. I am sure that they have been waiting for my confirmation emails.
# Posted By james | 9/18/19 11:55 AM
UAN or Universal Account Number is essential for you to access your PF records and ensure all your savings are being credited to your account. Accessing the UAN Member Portal at www.epfindia.gov.in through your UAN will help you simplify the various tasks that otherwise would have meant visiting your local Employees’ Provident Fund Organisation or EPFO office.
# Posted By Activate UAN Online | 9/22/19 10:52 AM
Thank you for the sensible critique. Me & my neighbour were preparing to do some research about that. We got a good book on that matter from our local library and most books where not as influensive as your information
# Posted By voyance par telephone | 9/30/19 11:02 AM
Nicely well-written article. It was an awesome article to read. Complete rich content and fully informative https://www.digitekprinting.com/coroplast-signs

# Posted By carl | 10/2/19 12:30 PM
Enter your Universal Account Number, mobile number and PF member ID. Enter the captcha characters. Click on ‘Get authorization PIN’ button. You will receive the PIN on your registered mobile number. Click on ‘I Agree’ under the Disclaimer checkbox and enter the OTP that you receive on your mobile number and click on ‘Validate OTP and Activate UAN’.
# Posted By EPF India Complaint Status Check | 10/5/19 1:05 PM
Thanks so much with this fantastic new web site. I’m very fired up to show it to anyone. It makes me so satisfied your vast understanding and wisdom have a new channel for trying into the world.
# Posted By Situs Tembak Ikan | 10/8/19 7:26 AM
Yes i am totally agreed with this article and i just want say that this article is very nice and very informative article.I will make sure to be reading your blog more. You made a good point but I can't help but wonder, what about the other side? !!!!!!Thanks   
# Posted By ????? | 11/23/19 11:05 AM

© 2020, Stephen J. Withington, Jr.  |  BlogCFC was created by Raymond Camden – Version 5.9.004

Creative Commons License  |  This work is licensed under a Creative Commons Attribution 3.0 Unported License.  |  Hosted by Hostek.com