Developer Support »

Email templates

Applies to the Pro version only

By default the script formats the output email in a certain way, be it the standard output email or the autoresponse email. This format is simple, clean and basic. For plain text emails, the output shows the form field names together with the submitted data. For HTML formatted emails, the same information is shown in a table, with the field names in bold. There is a limited amount of customization you can do with these.

If you have a need for formatting the output email in a particular way, then you can use a template to make the body of the email, which means it can appear exactly as you want it to, be it plain text or HTML. The template file is just an ordinary text file. You can write it in straight plain text or you can write it in HTML, just like you were writing a web page. You can do this for the standard email output from the script and also for the autoresponse email that gets sent to your visitor. You must make a template file and upload it to your server and configure the script (formtoemailpro.php) accordingly.

Making a plain text template file
Open a new blank file in a text editor (such as Notepad) and save it as "email_template.php". Write the text in the file just as you would like the email to appear. To show submitted values from the form, use this placeholder:

ff<form_field>

Replace form_field with the name of the form field you want to get the data from. Here's an example. Suppose you have these inputs on your form:

<input type="text" name="name">
<input type="text" name="email">
<input type="text" name="state">

You could put this text in your email template file:

Message from ff<name>.
The visitor's email address is: ff<email>
The visitor is from ff<state>.

Suppose the visitor enters his name as Bob, and his email address is [email protected] and he is from Texas. This will produce the following text in the email you get:

Message from Bob.
The visitor's email address is: [email protected]
The visitor is from Texas.

With a plain text template, write the template exactly as you want it to appear in the email, like above. Line breaks are automatically converted, so you can make new lines or paragraphs and these will be replicated in the email you get. So effectively you are just writing the email as you want to get it but using the ff<form_field> placeholders where appropriate.

When you have written the template file, save it as "email_template.php" and upload it to the same directory/folder as the script (formtoemailpro.php). These are default settings. For using other filenames or directories, see below.

Important. Write the form field in the placeholder EXACTLY as it appears in your form. So if you have an input on your form like this:

<input type="text" name="First_NAME">

You would use ff<First_NAME> in your template.

Making an HTML template file
As before, and using the example form values above, open a new blank file in a text editor (such as Notepad) and save it as "email_template.php". Write the HTML code in the file just as you were writing a webpage. To show submitted values from the form, use the same placeholder above. Here's an example of an HTML email template:

<html>
<head>
<title>Message from ff<name></title>
</head>
<body>
<p>A message from <b>ff<name></b> whose email address is ff<email> and who is from ff<state>.</p>
</body>
</html>

For HTML emails you should use very simple and often deprecated HTML. This is due to notoriously poor support for HTML in email readers. Equally, support for CSS isn't great. Experiment with your own email program.

Save the above code and upload the file to your server. If using an HTML template, you need to enable the $html_format option in the script.

Showing script-generated values
The above examples use values from your form. There are some values generated by the script that you might want to show in your templates. Some of them need to be enabled in the script options first. You can get more information in the script instructions about that. The script-generated values are: Sender's IP address, Date and time submitted, Message ID, attachment filenames and links to files uploaded to your server. To use these values in your template (subject to them being enabled where appropriate) use this code:

ff<Sender's IP address>
ff<Date submitted>
ff<Message ID>
ff<file_input> where file_input is the name of the file input on your form. Use this for showing attachment filenames and links to uploaded files.

Email subject
A template only makes the body of the email. Enter the subject for the email in the configuration option in the script. You can do various things with the subject, including using values from your form. Have a look at the "Email subject" page in the support section for more information.

Using another directory for the template
You can upload the email template file to any directory/folder on your server. Conventionally, include files such as these are kept outside the web-accessible directories. You can state a different directory/folder in the script configuration options. Here's an example:

$email_template_filename = "/home/bob/includes/email_template.php";

Using a template for the autoresponse email
You can configure the script to use a template for the autoresponse email too. This is done in the same way as configuring it to use a template for the standard output email. You can see instructions in the script for this.