Tectite Forums

Welcome to the Tectite Forums! You can download and get support for our free PHP FormMail (form processor) and other free software.


Go Back   Tectite Forums > FormMail Support > HOWTO Guides and Tips
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Vote for FormMail
at Scripts.com

Vote for FormMail at
FatScripts!

Vote for FormMail at
ScriptSearch.com

Vote for FormMail
at HotScripts.com

Closed Thread
 
Thread Tools Display Modes
  #1  
Old 01-May-2004, 04:05 AM
russellr's Avatar
russellr russellr is offline
Tectite and FormMail Author
 
Join Date: Dec 2003
Posts: 3,372
russellr is on a distinguished road
Default Sending form results in an HTML email

This post describes how to setup FormMail and your form so that the results are sent to you in an HTML email.

Before attempting this, first ensure you've got FormMail working with your form and sending you plain text emails.

Overview

Here are the steps in broad overview:
  1. Create an HTML document that will be used by FormMail as a template for your email. This can be a modified copy of your form, for example.
  2. Create a directory on your server to hold your HTML template(s).
  3. Upload your HTML template from step 1 to the directory you created in step 2.
  4. Configure FormMail: set $TEMPLATEDIR to the pathname of the directory you created in step 2.
  5. Add a hidden field to your form called "mail_options". In this field specify the option "HTMLTemplate" and set it to the name of the HTML template you created in step 1.
Step 1 - Create an HTML template

FormMail sends you HTML email by taking the fields from a form submission and putting their values into HTML document you've created. This document is a template because you use a special syntax to tell FormMail where you want each field.

It's very simple to do this: you create an HTML document, using your favourite HTML editor, that looks the way you want.

Then, wherever you want a field, you place the field name and prefix it with a dollar sign ($). The field names are the names you've used in your form.

Here's a very simple and short HTML template:
Code:
<html>
<body>
<p>Here is the latest form submission from your website:</p>
<br />User's name: $realname
<br />Email address: $email
<br />Their comments:
$comments
</body>
</html>
This template is similar, but puts the form results in a table:
Code:
<html>
<body>
<p>Here is the latest form submission from your website:</p>
<table border="1">
<tr>
    <td>User's name:</td>
    <td><b>$realname</b></td>
</tr>
<tr>
    <td>Email address:</td>
    <td><b>$email</b></td>
</tr>
<tr>
    <td>Their comments:</td>
    <td><b>$comments</b></td>
</tr>
</table>
</body>
</html>
Step 2 - Create a directory

This is an important security requirement. By creating a special directory on your server to hold all your templates, you can ensure that an attacker cannot download files that you don't want anyone to see.

Without this step, it might be possible for an attacker to read your password file or some other secure location on your server.

Create a directory called "fmtemplates" at the top of your web server document root.

Step 3 - Upload your template

Now upload the template you created in step 1 to the directory you created on your server in step 2.

You can use any file name for the template, but let's assume you've called the template "mytemplate.htm".

Step 4 - Configure FormMail

You've done this before, so you shouldn't have any trouble. Simply find the line containing $TEMPLATEDIR in the configuration section.

In version 8.16, $TEMPLATEDIR is defined around line 330.

Set it to the full path of the directory you created in step 2. For example:
PHP Code:
$TEMPLATEDIR "/home/your-name/www/fmtemplates"
Step 5 - Tell your form to use it

Now edit your HTML form. You've already set it up to use FormMail, so the only thing to do is to put a hidden field in to tell FormMail you want it to send the form results via the HTML template.

To do this, just add a hidden field called "mail_options", like this:
Code:
<input type="hidden" name="mail_options"
value="HTMLTemplate=mytemplate.htm" />
That's it.

If you've managed to follow the steps correctly, your form submissions will now be sent to you in HTML format.

Note, however, prior to version 8.13 of FormMail, that the user must fill in all the fields specified by your template. Therefore, you need to make these required fields, or use the TemplateMissing mail_option. From version 8.13, missing fields are simply replaced by a blank, and you can use TemplateMissing to provide a different value.

Code:
<input type="hidden" name="required"
value="realname,email,comments" />
and/or:

Code:
<input type="hidden" name="mail_options"
value="HTMLTemplate=mytemplate.htm,TemplateMissing=N/A" />
If you have any problems, you're welcome to submit a question in our forums.

Other things

Once you've got your HTML form working with an HTML template, there may some tweaking you want to do.

Here's are some ideas:
  • I only want the HTML, no plain text.
By default, FormMail sends a multi-part MIME message which has the form submissions in two formats. The first format is plain text (just like FormMail sent before), and the second format is your HTML template.

Most mail readers know how to treat the email correctly and just show you the HTML version.

If you're having problems with the plain text showing, or you simply want to reduce the size of the emails you receive, you can switch off the plain text version. In "mail_options", simply specify "NoPlain".

Like this:
Code:
<input type="hidden" name="mail_options"
value="HTMLTemplate=mytemplate.htm,NoPlain" />
  • My TEXTAREA fields have all the lines joined together.
This is the default action for FormMail. To get FormMail to keep lines separate, in "mail_options", simply specify "KeepLines".

Like this:
Code:
<input type="hidden" name="mail_options"
value="HTMLTemplate=mytemplate.htm,KeepLines" />
  • I want something special to show blank fields.
Often you'll want FormMail to replace blank fields with another character sequence, rather than fail with an error.

The following example will show "N/A" wherever a form field is empty or not provided by the user:

Code:
<input type="hidden" name="mail_options"
value="HTMLTemplate=mytemplate.htm,TemplateMissing=N/A" />
Good luck, and if you have any suggestions for new features you'd like to see, please let us know!
__________________
Russell Robinson (Author of Tectite FormMail and FormMailDecoder)
Root Software (http://www.tectite.com/)

Last edited by russellr : 11-Sep-2009 at 08:58 PM.
  #2  
Old 22-Sep-2004, 01:01 PM
michealbryant michealbryant is offline
Junior Member
 
Join Date: Sep 2004
Posts: 3
michealbryant is on a distinguished road
Cool Re: Sending form results in an HTML email

can we get radio buttons information through an html form template... your informations dont cover this issue?

May be a silly one and would be cool if we can.

Mike
  #3  
Old 22-Sep-2004, 09:22 PM
russellr's Avatar
russellr russellr is offline
Tectite and FormMail Author
 
Join Date: Dec 2003
Posts: 3,372
russellr is on a distinguished road
Default Re: Sending form results in an HTML email

Hi,

You can display the selected value of a set of radio buttons, but you can't show radio buttons in the template.

For example, with this form:
Code:
What do you like?
Noise: <input type="radio" name="likes" value="noise" />
Silence: <input type="radio" name="likes" value="silence" />
You can do this in your template:
Code:
Person likes: $likes
which will show as:

Code:
Person likes: noise
or
Code:
Person likes: silence
To show as radio buttons instead is quite tricky. However, we do have the technology to achieve this, so we've put the idea on our TO-DO list for FormMail.
__________________
Russell Robinson (Author of Tectite FormMail and FormMailDecoder)
Root Software (http://www.tectite.com/)
  #4  
Old 23-Sep-2004, 08:54 AM
michealbryant michealbryant is offline
Junior Member
 
Join Date: Sep 2004
Posts: 3
michealbryant is on a distinguished road
Question Re: Sending form results in an HTML email

Hi Russel

Thanks for the response
I have set the template up but when I submit I get the following error report

An error occurred while processing the form.

Please contact us directly since this form is not working.
We apologize for any inconvenience this error may have caused.

I have an attach feature set up on my form is this affecting the submission of my form results by html template?

Mike
  #5  
Old 23-Sep-2004, 11:14 AM
russellr's Avatar
russellr russellr is offline
Tectite and FormMail Author
 
Join Date: Dec 2003
Posts: 3,372
russellr is on a distinguished road
Default Re: Sending form results in an HTML email

Hi,

You'll need to set DEF_ALERT in FormMail so that you get an alert message sent to you.

The alert message will tell us what the problem is.
__________________
Russell Robinson (Author of Tectite FormMail and FormMailDecoder)
Root Software (http://www.tectite.com/)
  #6  
Old 23-Sep-2004, 11:46 AM
michealbryant michealbryant is offline
Junior Member
 
Join Date: Sep 2004
Posts: 3
michealbryant is on a distinguished road
Talking Re: Sending form results in an HTML email

Russell

You are the man! This script is awesome and the form works like a treat!!

Now to have some fun!

Mike
  #7  
Old 15-Oct-2004, 06:22 PM
sebestyen sebestyen is offline
Junior Member
 
Join Date: Oct 2004
Posts: 6
sebestyen is on a distinguished road
Default Re: Sending form results in an HTML email

Hey Russell,

Is there any way to get "zero" values passed through the script? What I mean is I can use "TemplateMissing=N/A" to get "N/A" printed in an HTML email for fields that did not have any data input but when they put a "0" (zero) in the field, the script returns "N/A" in the email.

Thanks,

sebestyen
  #8  
Old 15-Oct-2004, 08:59 PM
russellr's Avatar
russellr russellr is offline
Tectite and FormMail Author
 
Join Date: Dec 2003
Posts: 3,372
russellr is on a distinguished road
Default Re: Sending form results in an HTML email

Hi,

Well, you could make "TemplateMissing=0" (zero), but that's going to look funny on text fields.

Another way would be to provide an initial value of "0" on your numeric fields.

Make the non-required numeric fields initially zero, and leave the required numeric fields blank (and put them in the "required" specification).
__________________
Russell Robinson (Author of Tectite FormMail and FormMailDecoder)
Root Software (http://www.tectite.com/)
  #9  
Old 14-Feb-2005, 01:43 PM
Jackal Jackal is offline
Junior Member
 
Join Date: Feb 2005
Posts: 12
Jackal is on a distinguished road
Default Re: Sending form results in an HTML email

Russell, your FormMail is great! But I have one question:

I've got 14 select boxes in my form, the visitor can select the documentation he wan't to obtain.

In my form it's like this: <input type="check-box" name="document1" value="Documentation_Name">

I've got something like this in my HTML template:

<table>
<tr>
<tdDocumentation:</td>
</tr>
<tr>
<td>
$document1<br>
$document2<br>
$document3<br>
$document4<br>
</td>
</tr>
</table>

But when they only want to obtain document4, I have 3 empty lines in my mail.. When I remove the <br> tags, all the documents are put together as one line. When I put them in seperate <td>'s I get a load of empty TD's and the result is the same.

Is there a way to only show the lines that are filled? (skip some code or something). I can't use PHP in the template can I?
  #10  
Old 14-Feb-2005, 09:44 PM
russellr's Avatar
russellr russellr is offline
Tectite and FormMail Author
 
Join Date: Dec 2003
Posts: 3,372
russellr is on a distinguished road
Default Re: Sending form results in an HTML email

Hi,

That's a limitation of HTML.

FormMail can help you out though.

BTW, if you have this:

Code:
<input type="check-box" name="document1" value="Documentation_Name">
it should be this:

Code:
<input type="checkbox" name="document1" value="Documentation_Name">
(no hyphen)

Step 1

Instead of 4 different checkbox fields, make it one checkbox field, like this:

Code:
Document 1: <input type="checkbox" name="documents[]" /> <br />
Document 2: <input type="checkbox" name="documents[]" /> <br />
Document 3: <input type="checkbox" name="documents[]" /> <br />
Document 4: <input type="checkbox" name="documents[]" /> <br />
Now, in your template, you can just refer to $documents:

Code:
<table>
<tr>
<tdDocumentation:</td>
</tr>
<tr>
<td>
$documents
</td>
</tr>
</table>
That get's the data in with comma separators.

Step 2

If you want them on separate lines, add the following to your form:

Code:
<input type="hidden" name="template_list_sep" value="<br />" />
FormMail will now put "<br />" between each item in the list and you'll get exactly the right number of lines.

Enjoy!

BTW, yes, your templates can be PHP. You just need to tell FormMail to open then as URLs instead of files (set $TEMPLATEURL instead of $TEMPLATEDIR).
__________________
Russell Robinson (Author of Tectite FormMail and FormMailDecoder)
Root Software (http://www.tectite.com/)
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Sample HTML Form Using FormMail russellr FormMail 1 21-Mar-2007 06:49 AM
send an email in HTML michecosta FormMail Subscription Support 3 25-May-2004 08:18 PM
Submitted form output onto HTML page? LKimber FormMail Subscription Support 2 13-Apr-2004 10:39 AM
not seeing form data brownie FormMail Subscription Support 6 19-Jan-2004 01:37 AM
Help trying to set up a form to email and send info to file rridsdale FormMail Subscription Support 1 14-Jan-2004 02:38 AM


All times are GMT. The time now is 08:50 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Copyright © 2004-present Open Concepts (Vic) Pty Ltd.
We use dedicated servers from HiVelocity.net.