USING CMSB EMAIL TEMPLATES - Nov 14th, 2016
|
Email Templates are really easy to use, but they can seem pretty confusing , so with the help of Ross Fairbain from Interactive Tools, here's a simple recipe to help understand the process.
Let's say that you want to send an email to specific individuals each time a form is submitted on your site (or for any other purpose).
He said (edited):
For my example, I'll assume that you have a simple email form on your site that lets visitors email comments to you. The form has 3 fields. Name, Email and Comment.
Something like:
<form method="post" action="?"> <input type="hidden" name="save" value="1" /> <table border="0" cellspacing="0" cellpadding="2"> <tr> <td>Name</td> <td><input type="text" name="name" value="<?php echo htmlencode(@$_REQUEST['name']); ?>" size="50" /></td> </tr> <tr> <td>Email</td> <td><input type="text" name="email" value="<?php echo htmlencode(@$_REQUEST['email']); ?>" size="50" /></td> </tr> <tr> <td>Comment</td> <td><textarea name="comment" COLS=50 ROWS=6><?php echo htmlspecialchars(@$_REQUEST['comment']); ?></textarea></td> </tr> <tr> <td colspan="2" align="center"> <input class="button" type="submit" name="submit" value="Send Us Your Comments >>" /> </td> </tr> </table> </form>
The first thing we'll look at is the code you need on your web page (the one with the form):
$emailHeaders = emailTemplate_loadFromDB(array( 'template_id' => 'COMMENT-TO-ADMIN', 'placeholders' => array( 'user.name' => $_REQUEST['name'], 'user.email' => $_REQUEST['email'], 'user.comment' => $_REQUEST['comment'],
))); $mailErrors = sendMessage($emailHeaders);
You can put this after any error checking you're doing when the form is submitted. Just make sure that it appears before any code that clears your form values, like:
$_REQUEST = array(); // clear form values
Next, you need to log into CMS Builder and create a new email template. ***Make sure you do this in the Email Templates section under CMS Setup (or under Admin if prior to V 3).***
Here's an example of how you might fill in the fields in the Email Template:
Template ID => COMMENT-TO-ADMIN Description => This email gets sent to site admin each time the comment form is submitted From => #user.email# To => #settings.adminEmail#
Subject => New Comment From #user.name# Message HTML => #user.comment#
And then leave everything else as it is.
Things to note here:
1. You can see that anything set as a "placeholder" in PHP is available in the email template with the hash marks. Ex: 'user.name' in PHP becomes #user.name# in the template.
2. Placeholder names are completely customization. Ex: 'user.name' could just be 'name', or' first_name'. Sometimes you'll want to have a lot of placeholders and naming them specifically helps organize things. No spaces are allowed so just use . or _ or - instead.
3. There are several placeholders available to every email template. Ex: #settings.adminEmail#. You'll see a full list of those in the email template under the "Instructions" heading in your new email template.
4. Placeholders can be variables that pull information from your database. For example, they can define the To and CC email addresses in the template. So, for example, if you have a particular position in your organization that handles these types of comment submissions, you can create a variable on your form page like:
$service_rep = strtolower($organization_informationRecord['service_rep_email']); // a field in a single record editor on your site called "Organization Information"
then in the placeholders array, create the place holder
'service_rep' => $service_rep,
Then use #service_rep# as the "to" address in the email template.
You can also use plain email addresses, like someone@mydomain.com in the "to", "CC", and "BCC" Fields in the template.
|
The materials on this web site have been created for use with CMS Builder content management software. CMS Builder software is published and licensed for use by InteractiveTools.com. Please contact
Interactive Tools for information on the downloading of the software or the purchasing of licenses.