Bookmark and Share

ASP Email Form

You can easily add limited email functionality to your ASP programs using the Message object. The Message object is not very feature intensive, but this lesson will show you how to implement a basic email form on your ASP site.

Advertise on

Experienced web masters might have noticed that whenever you put your email address onto the internet, so that your visitors can email you, you instantly get hit with tons of spam. This is most likely because a spammer's email finder application saw your email address and added it to their nasty hit list.

You can receive emails from your visitors, without letting the general public know your email address, using what is taught in this lesson.

Quicky HTML Form

Before we start worrying about how to send the email, let's make a basic HTML form that will gather the following information from the user:

  • From
  • To
  • Subject
  • Body

Our HTML file will be called "tizagEmailForm.html" and should be saved in a directory that can Run ASP.

tizagEmailForm.html Code:

<form method="POST" action="tizagEmail.asp">
To <input type="text" name="To"/> <br />
From <input type="text" name="From"/> <br />
Subject <input type="text" name="Subject"/> <br />
Body <textarea name="Body" rows="5" cols="20" wrap="physical" > 
<input type="submit" />

If you would like a refresher on HTML Forms check out our HTML Forms Lesson.

ASP NewMail Object Death

Microsoft has made it rather confusing by changing their implementations of sending mail with ASP. In older ASP versions you would send mail with the NewMail Object. However, new versions of Microsoft's Internet Information Services (IIS) software has changed again to instead use the Message object.

ASP Mail Processor

Now that we have our handy dandy HTML Form we need to create the ASP file that will retrieve this data and shoot off an email. All the properties that are set in the following code are self-explanatory and write only. Also, because Message is an object, it must be Set equal to nothing after we have finished with it to release the memory allocated to it.

The name of the ASP file is "tizagEmail.asp" and should be saved to the same directory as "tizagEmailForm.html".


'Sends an email
Dim mail
Set mail = Server.CreateObject("CDO.Message")
mail.To = Request.Form("To")
mail.From = Request.Form("From")
mail.Subject = Request.Form("Subject")
mail.TextBody = Request.Form("Body")
Response.Write("Mail Sent!")
'Destroy the mail object!
Set mail = nothing

Please note that this is a very basic ASP Email Form and is only for education purposes. If you were to put an email form on your web site you would want to do some checking to make sure the email addresses are valid, allow for attachments, etc.

Bookmark and Share

Found Something Wrong in this Lesson?

Report a Bug or Comment on This Lesson - Your input is what keeps Tizag improving with time!

Advertise Here

More Tutorials!
Microsoft Office Tutorials Artist Tutorials