Click here to Skip to main content
11,584,208 members (55,167 online)
Click here to Skip to main content

A versatile HTML form mail script for classic ASP

, 15 Mar 2006 373.8K 8.4K 59
Rate this:
Please Sign up or sign in to vote.
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! Smile | :)

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

Share

About the Author

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


You may also be interested in...

Comments and Discussions

 
QuestionError when submit from non IE browser Pin
infogmt15-May-12 21:53
memberinfogmt15-May-12 21:53 
GeneralMy vote of 5 Pin
manoj kumar choubey27-Apr-12 1:28
membermanoj kumar choubey27-Apr-12 1:28 
GeneralForm submit to server Pin
Ajay Kale New18-Oct-10 20:48
memberAjay Kale New18-Oct-10 20:48 
GeneralMy vote of 5 Pin
Roy Ritchie12-Jul-10 23:47
memberRoy Ritchie12-Jul-10 23:47 
GeneralStop using this script! It is YEARS out of date! Pin
Nathan Ridley24-Aug-08 15:30
memberNathan Ridley24-Aug-08 15:30 
GeneralRe: Stop using this script! It is YEARS out of date! Pin
adstatus24-Aug-08 15:54
memberadstatus24-Aug-08 15:54 
GeneralRe: Stop using this script! It is YEARS out of date! Pin
teddio15-Sep-09 9:56
memberteddio15-Sep-09 9:56 
QuestionLaunching Script problems Pin
adstatus24-Aug-08 13:50
memberadstatus24-Aug-08 13:50 
QuestionCDO.Message.1 error '80040220' Pin
Desmond chee20-Aug-08 18:10
memberDesmond chee20-Aug-08 18:10 
AnswerRe: CDO.Message.1 error '80040220' Pin
alimzhan2-Feb-09 9:46
memberalimzhan2-Feb-09 9:46 
AnswerRe: CDO.Message.1 error '80040220' Pin
shant19764-Nov-09 11:44
membershant19764-Nov-09 11:44 
GeneralWhere to add smtp server name within asp file Pin
sonal130723-May-08 15:37
membersonal130723-May-08 15:37 
GeneralRe: Where to add smtp server name within asp file Pin
Nathan Ridley23-May-08 15:42
memberNathan Ridley23-May-08 15:42 
QuestionRobots filling out form Pin
jadams746930-Nov-07 10:17
memberjadams746930-Nov-07 10:17 
AnswerThe &quot;SendUsing&quot; configuration value is invalid. [modified] Pin
PR_Worldofrugs22-Oct-07 7:31
memberPR_Worldofrugs22-Oct-07 7:31 
Questioncan form output be saved to a file aswell? Pin
dannif29-Aug-07 5:27
memberdannif29-Aug-07 5:27 
Questionerror '8004020d' Pin
mccallchick8-Aug-07 14:44
membermccallchick8-Aug-07 14:44 
AnswerRe: error '8004020d' Pin
alimzhan2-Feb-09 9:47
memberalimzhan2-Feb-09 9:47 
QuestionEmail not sending. Pin
deinemuse26-Jun-07 5:47
memberdeinemuse26-Jun-07 5:47 
GeneralNot all fields populating in email Pin
kenny78220-Apr-07 20:18
memberkenny78220-Apr-07 20:18 
GeneralRe: Not all fields populating in email Pin
kenny78222-Apr-07 11:43
memberkenny78222-Apr-07 11:43 
GeneralRe: Not all fields populating in email Pin
kenny78222-Apr-07 11:44
memberkenny78222-Apr-07 11:44 
QuestionDo not know how to use Pin
Chee Shai Choon3-Apr-07 7:47
memberChee Shai Choon3-Apr-07 7:47 
AnswerRe: Do not know how to use Pin
adstatus24-Aug-08 13:06
memberadstatus24-Aug-08 13:06 
QuestionCDO.Message.1 error '80040220' Pin
Nicola F15-Feb-07 15:33
memberNicola F15-Feb-07 15:33 
AnswerRe: CDO.Message.1 error '80040220' Pin
alimzhan2-Feb-09 9:47
memberalimzhan2-Feb-09 9:47 
GeneralI need a translator.. PLS!!! Pin
samblam20064-Feb-07 3:58
membersamblam20064-Feb-07 3:58 
GeneralThe &quot;SendUsing&quot; configuration value is invalid. Pin
andreakahle19-Jan-07 18:28
memberandreakahle19-Jan-07 18:28 
GeneralRe: The &quot;SendUsing&quot; configuration value is invalid. Pin
davehouse29-Jan-07 2:51
memberdavehouse29-Jan-07 2:51 
GeneralRe: The &quot;SendUsing&quot; configuration value is invalid. Pin
photo fx20-Jun-07 6:31
memberphoto fx20-Jun-07 6:31 
GeneralNice Piece of Script Pin
chris570322-Nov-06 9:22
memberchris570322-Nov-06 9:22 
QuestionRe: Nice Piece of Script Pin
PR_Worldofrugs22-Oct-07 7:51
memberPR_Worldofrugs22-Oct-07 7:51 
QuestionThe "SendUsing" configuration value is invalid. Pin
froggiemander10-Nov-06 13:42
memberfroggiemander10-Nov-06 13:42 
AnswerRe: The "SendUsing" configuration value is invalid. Pin
alimzhan2-Feb-09 9:48
memberalimzhan2-Feb-09 9:48 
GeneralAttachment mod sorted! Pin
oxonpete4-Nov-06 3:44
memberoxonpete4-Nov-06 3:44 
QuestionAttachment mod? Pin
oxonpete2-Nov-06 1:51
memberoxonpete2-Nov-06 1:51 
GeneralNot getting the email Pin
TCQ14-Sep-06 1:17
memberTCQ14-Sep-06 1:17 
GeneralRe: Not getting the email Pin
Nathan Ridley14-Sep-06 1:20
memberNathan Ridley14-Sep-06 1:20 
Generalnot getting the result I should from this Pin
aaaronnn8-Sep-06 8:49
memberaaaronnn8-Sep-06 8:49 
AnswerRe: not getting the result I should from this Pin
Nathan Ridley8-Sep-06 20:15
memberNathan Ridley8-Sep-06 20:15 
GeneralRe: not getting the result I should from this Pin
aaaronnn20-Sep-06 7:31
memberaaaronnn20-Sep-06 7:31 
GeneralRe: not getting the result I should from this Pin
rdriskill12-Nov-07 8:57
memberrdriskill12-Nov-07 8:57 
Generalproblem sorted - thanks anyway Pin
steve-site10028-Jul-06 14:13
membersteve-site10028-Jul-06 14:13 
Generalalmost got it working - help please Pin
steve-site10025-Jul-06 13:42
membersteve-site10025-Jul-06 13:42 
Generalwhere to insert the smtp-server.... Pin
d00_ape17-Jul-06 0:24
memberd00_ape17-Jul-06 0:24 
GeneralRe: where to insert the smtp-server.... Pin
id10t22-Jan-07 7:53
memberid10t22-Jan-07 7:53 
Generalsendmail asp Pin
bigjohn324-Jun-06 7:39
memberbigjohn324-Jun-06 7:39 
QuestionHow to attach a file to email via sendmail Pin
kenfresher1-Jun-06 10:11
memberkenfresher1-Jun-06 10:11 
QuestionForm results display Pin
richard derrick5-May-06 2:33
memberrichard derrick5-May-06 2:33 
Generalworks in testmode, doesn't outside of testmode Pin
hypnokizer28-Apr-06 11:29
memberhypnokizer28-Apr-06 11:29 

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

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

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150603.1 | Last Updated 16 Mar 2006
Article Copyright 2003 by Nathan Ridley
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid