ASP Express Home | What You Get | Pricing Information
New-->Online User Count
Using DatePart and other Date Functions
(Updated) Using Variables, Single & DoubleQuotes with SQL Statements in ASP
(Updated) Emailing Form Results
Mass Emailing with CDO
Using The Ad Rotator
ASCII Character Set 0-127
Emailing Form Results With CDO
Here's the Basic code for using CDO for emailing on an NT / IIS server. You must include the first section to instantiate the object, and the rest are the standard email sections. Be sure to fill in valid email addresses in the FROM and TO sections below.
Set objCDO = Server.CreateObject("CDO.message")
txtSubject = "This is what I wanted to write you about!"
objCDO.To = "Me@here.com"
objCDO.From = "firstname.lastname@example.org"
objCDO.bcc = "someoneelse@SomeOtherPlace.com"
objCDO.Subject = "You've gotta read this!"
objCDO.TextBody = txtSubject
As you can see, you can use standard variables for the different sections of a normal email.
So, if you want to use ASP to mail form results, just gather the data from the form at the top of the page, like you normally would, say, if you were going to use the form results to search a database, but this time, you don't need a connection to a database (unless you want to do that in addition to emailing).
I use 'str' to start out my string based variables to keep them straight in my mind and on the page. It's easier for me because I come from a VB background also. Once gathered, I go ahead & figure out how I want it formatted in the email message. Usually, it's something like this:
Last Name =(FormResult)
To do this, what you'd need to do is put it in a string that will end up being the objCDO.subject:
<% strBody="First Name=" & strFname & vbcrlf
strBody=strBody & "Last Name=" & strLname & vbcrlf
Naturally, you can put anything else here to include in the body (strBody) of the text also.
If you have quite a few fields, you might try something like this:
<% for x = 1 to request.form.count()
if request.form.item(x)<>"" then
if request.Form.item(x) <> "Submit" then
strBody=strBody & (request.form.key(x) & " = ")
strBody=strBody & (request.form.item(x) & vbcrlf)
You can repeat this code for the response to the page by changing the vbcrlf to <br>
Then, when you type in the 'TO' and 'FROM' names, and the subject, all you have to do is put in:
and format the rest of the Response page so that whoever filled out the form will know it's finished and the results have been emailed.
"Thank You for your input - your data has been received!"
That's all there is to it !
Attn: Paid ASP Express users - go back to your login page to download the sample files associated with this tutorial!
Of course, be sure to do all your ASP coding with :