Click here to Skip to main content
6,595,444 members and growing! (19,821 online)
Email Password   helpLost your password?
Web Development » ASP » General     Intermediate

A versatile HTML form mail script for classic ASP

By Nathan Ridley

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.
HTMLWin2K, WinXP, Win2003, ASP, Visual Studio, Dev
Posted:17 Nov 2003
Updated:15 Mar 2006
Views:248,933
Bookmarked:47 times
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
24 votes for this article.
Popularity: 5.68 Rating: 4.11 out of 5
4 votes, 16.7%
1

2
1 vote, 4.2%
3
5 votes, 20.8%
4
14 votes, 58.3%
5

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

About the Author

Nathan Ridley


Member
Web application developer, graphic designer, aspiring entrepreneur, snowboarder and electronic music afficianado.


Occupation: Web Developer
Location: Australia Australia

Other popular ASP articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 25 of 113 (Total in Forum: 113) (Refresh)FirstPrevNext
GeneralStop using this script! It is YEARS out of date! PinmemberNathan Ridley16:30 24 Aug '08  
GeneralRe: Stop using this script! It is YEARS out of date! Pinmemberadstatus16:54 24 Aug '08  
GeneralRe: Stop using this script! It is YEARS out of date! Pinmemberteddio10:56 15 Sep '09  
QuestionLaunching Script problems Pinmemberadstatus14:50 24 Aug '08  
QuestionCDO.Message.1 error '80040220' PinmemberDesmond chee19:10 20 Aug '08  
AnswerRe: CDO.Message.1 error '80040220' Pinmemberalimzhan10:46 2 Feb '09  
AnswerRe: CDO.Message.1 error '80040220' Pinmembershant197612:44 4 Nov '09  
GeneralHelp with this asap PinmemberNoughty9:54 2 Aug '08  
GeneralWhere to add smtp server name within asp file Pinmembersonal130716:37 23 May '08  
GeneralRe: Where to add smtp server name within asp file PinmemberNathan Ridley16:42 23 May '08  
QuestionRobots filling out form Pinmemberjadams746911:17 30 Nov '07  
AnswerThe "SendUsing" configuration value is invalid. [modified] PinmemberPR_Worldofrugs8:31 22 Oct '07  
Questioncan form output be saved to a file aswell? Pinmemberdannif6:27 29 Aug '07  
Questionerror '8004020d' Pinmembermccallchick15:44 8 Aug '07  
AnswerRe: error '8004020d' Pinmemberalimzhan10:47 2 Feb '09  
QuestionEmail not sending. Pinmemberdeinemuse6:47 26 Jun '07  
GeneralNot all fields populating in email Pinmemberkenny78221:18 20 Apr '07  
GeneralRe: Not all fields populating in email Pinmemberkenny78212:43 22 Apr '07  
GeneralRe: Not all fields populating in email Pinmemberkenny78212:44 22 Apr '07  
QuestionDo not know how to use PinmemberChee Shai Choon8:47 3 Apr '07  
AnswerRe: Do not know how to use Pinmemberadstatus14:06 24 Aug '08  
QuestionCDO.Message.1 error '80040220' PinmemberNicola F16:33 15 Feb '07  
AnswerRe: CDO.Message.1 error '80040220' Pinmemberalimzhan10:47 2 Feb '09  
GeneralI need a translator.. PLS!!! Pinmembersamblam20064:58 4 Feb '07  
GeneralThe "SendUsing" configuration value is invalid. Pinmemberandreakahle19:28 19 Jan '07  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 15 Mar 2006
Editor: Rinish Biju
Copyright 2003 by Nathan Ridley
Everything else Copyright © CodeProject, 1999-2009
Web22 | Advertise on the Code Project