Click here to Skip to main content
15,885,216 members
Articles / Web Development / HTML
Article

A versatile HTML form mail script for classic ASP

Rate me:
Please Sign up or sign in to vote.
4.68/5 (26 votes)
15 Mar 20063 min read 494.7K   9.4K   60   117
This script allows you to email the contents of an HTML form to one or more specified addresses. It supports HTML emails, plain text emails, and preformatted email templates.

Introduction

I submitted this article because I found it to be of great use and it does a good job of supporting all my form emailing needs. If you find it useful, then great! :)

Usage

It's quite simple to use, all you need to do is the following:

  1. The sendmail.asp file.
  2. An HTML page with a form that needs to be emailed (making sure certain required hidden fields are included).
  3. A thanks page to redirect to when the mail send is complete.
  4. An optional email template to define how the form contents should be formatted in the email that is sent.

The script supports plain text and HTML email formats. If you want to send an HTML email, you must create an email template first. You can use a plain text email template instead if you like, and if you prefer not to use HTML but still want to make sure the email is formatted nicely.

In your email template, you should put placeholders for each form element submitted. The placeholders should be formatted like this: [$form-field-name$]. For example, if you have a text field called "surname", your placeholder in the template should read: [$surname$]. The zip file for this article contains a sample email template for you to look at.

A set of hidden fields is required in your form so that the sendmail script knows what to do with the contents of the form, and where and how to send it. If applicable, you can replace some of the hidden fields with real fields to allow users to customize, for example, whom to send the mail to, or what the subject line in the email should be. The fields that the sendmail script understands are:

  • redirect - required

    The URL to redirect to when the mail has been sent.

  • mailto - required

    The email address of the recipient (separate multiple recipients with commas).

  • cc

    The email address of the cc recipient (separate multiple recipients with commas).

  • bcc

    The email address of the bcc recipient (separate multiple recipients with commas).

  • mailfrom - required

    The email address of the sender.

  • subject - Required, if no email template is specified.

    The subject line of the email.

  • message

    An optional message to include before the contents of the form in the email. Only used if no email template is specified.

  • template

    A relative path to a plain text or HTML file to use as an email template.

  • html

    Must be "yes" or "no". If yes, the email will be sent as an HTML email, otherwise, it'll be sent as a plain-text email.

  • testmode

    Must be "yes" or "no". If yes, the email will not be sent. Instead, the email will be written to the screen, with no redirection to the thanks page specified by the "redirect" field. This should be used to test the form and the email templates to make sure you are happy with the results.

Make sure that the form points to the sendmail.asp file, and that the method is set to "post". e.g. <form action="sendmail.asp" method="post">

The included zip file contains a sample form with validation, a sample email template, thanks page and of course, the script.

History

  • 18th November, 2003
    • Article posted.
  • 15th March, 2006
    • A CDO version of the script has now been included that should work on most new servers where the old one was failing. It also has a feature to hide email addresses from the hidden fields if desired. Just open the ASP file for a detailed explanation.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Australia Australia
Web application developer, graphic designer, aspiring entrepreneur, snowboarder and electronic music afficianado.


Comments and Discussions

 
GeneralRe: submit button doesn't work Pin
morgan858-Feb-06 4:58
morgan858-Feb-06 4:58 
GeneralError line 110 in sendmail.asp Pin
toloekka15-Jan-06 1:22
toloekka15-Jan-06 1:22 
Generaldon't get e mail Pin
dejanc9-Jan-06 2:10
dejanc9-Jan-06 2:10 
Question...send attachments? Pin
shaggy_the_shee[25-Oct-05 1:29
shaggy_the_shee[25-Oct-05 1:29 
GeneralSenders email from email field Pin
RolandRogers5-Oct-05 19:26
RolandRogers5-Oct-05 19:26 
AnswerRe: Senders email from email field Pin
shaggy_the_shee[25-Oct-05 1:35
shaggy_the_shee[25-Oct-05 1:35 
Questiondropdown with multiple option values and default subject field Pin
j-93-Oct-05 10:49
j-93-Oct-05 10:49 
GeneralAUTORESPONDER after submittal Pin
ewarner17-Aug-05 5:14
ewarner17-Aug-05 5:14 
Generalsubmitter copy Pin
jonmurray23-May-05 0:13
jonmurray23-May-05 0:13 
GeneralRe: submitter copy Pin
Nathan Ridley23-May-05 1:08
Nathan Ridley23-May-05 1:08 
GeneralRe: submitter copy Pin
jonmurray23-May-05 1:54
jonmurray23-May-05 1:54 
GeneralServer Trying to Display ASP page Pin
llpaul24-Jan-05 10:15
llpaul24-Jan-05 10:15 
GeneralRe: Server Trying to Display ASP page Pin
llpaul24-Jan-05 10:22
llpaul24-Jan-05 10:22 
GeneralRe: Server Trying to Display ASP page Pin
tojamismis24-Jan-05 11:17
tojamismis24-Jan-05 11:17 
GeneralRe: Server Trying to Display ASP page Pin
docaudiochris26-Jun-05 8:07
docaudiochris26-Jun-05 8:07 
QuestionHow do I make some fields required? Pin
sitruc23-Nov-04 20:55
sitruc23-Nov-04 20:55 
AnswerRe: How do I make some fields required? Pin
Nathan Ridley23-Nov-04 21:51
Nathan Ridley23-Nov-04 21:51 
Generalerror in with POST method Pin
floormongrel13-Oct-04 11:13
floormongrel13-Oct-04 11:13 
GeneralRe: error in with POST method Pin
Nathan Ridley13-Oct-04 11:20
Nathan Ridley13-Oct-04 11:20 
GeneralRe: error in with POST method - ME TOO! please reply!!!! Pin
morgan8510-Feb-06 4:37
morgan8510-Feb-06 4:37 
GeneralFields dont populate when testmode turned off Pin
shawnash30-Aug-04 16:30
shawnash30-Aug-04 16:30 
GeneralRe: Fields dont populate when testmode turned off Pin
Anonymous31-Aug-04 6:31
Anonymous31-Aug-04 6:31 
GeneralRe: Fields dont populate when testmode turned off Pin
Nathan Ridley26-Sep-04 17:04
Nathan Ridley26-Sep-04 17:04 
GeneralUsing a List/Menu form element Pin
balto8110-Jul-04 20:26
balto8110-Jul-04 20:26 
Generalasp emailing form contents problem Pin
asylum26917-Jun-04 4:08
asylum26917-Jun-04 4:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.