 |
Further
Reading ...
|
|
Do you own your own name? Do you own yourownname.com ? How about .net , .org or .biz ? Owning your own domain name is like owning your piece of real estate on the internet. http://www.quickregister.biz Hey, some domain have sold for millions of dollars. Here are some...
Is Your Niche Site A Real Lemon? By now many of you have heard about the advantages of building niche web sites to promote the selling of products and services online. Indeed, building a targeted niche site is a very smart idea. Because of the huge amount of competition from...
Cisco CCNA Tips: Four Tips To Pass The Exam! There are plenty of articles out there about how to prepare for the CCNA exam. However, there are also things you can do to increase your chances of success on exam day during the most important part of the entire process -- the time that you're...
Choosing the Best Printers
If you are settling for color printing or be it black and white, you should take all considerations in choosing and purchasing your printers. But choosing a printer is really a hard task. Imagine you have to choose from a hundred types of...
|
|
|
Emailing Form Input Using ASP
|
 |
Written By:
Amrit Hallan
|
|
|
Everybody uses online forms these days, whether to get user feedback or to get orders. They present your visitors with a means to convey their message to you.
Most of the webmasters prefer using CGI scripts for processing and emailing form inputs. Such scripts are copiously available, mostly free, at various free-scripts resources on the Net. Most of CGI happens in Perl, so you gotta be in friendly terms with the scripting language in order to fine tune the form-handling script according to your own, special needs.
A better alternative is, using either ASP or PHP. Both scripting languages are easy to use and require less coding. In Perl, if you write a routine in 50 lines, the same routine can be written, in say, 10 lines in ASP.
In this article I'm going to tell you how to write an HTML-form handling script in ASP. This script does two things - it emails you the details entered by the visitor, and then it displays a thank you page. It also checks if the user has left a relevant field, here, email, blank.
There are basically two email handling objects used by the servers supporting the ASP capability, viz., CDONTS and SMTP. We'll see how both work.
First, let us make an HTML page that contains our form (note that every HTML tag is preceded by a dot so that some of the email clients don't throw up a tantrum - you'll have to remove them before implementing the code):
"form.html"
. . . This is a test page to run an ASP script that handles form input.
. .
And now we write the ASP file that handles the required script to process the above form. Remarks are inserted using ' .
"emailform.asp"
.<% @Language = VBScript %> .<% Option Explicit %> .<% Response.Buffer = True %>
' You'll need the above command in case you want to show a "Thank you" page, as you'll need to "re-direct" to "thankyou.html".
. . . The form handling script. .
.
.<% Dim nName, eEmail, AllOk, bText, Mailer AllOk = True
' We use AllOk to see whether it is Ok to proceed further or not. If AllOk - continued below ...
|
|
|
continued ...
contains "False," we do not proceed. The use of AllOk here may seem needless here, but if there are many fields, it comes handy.
nName = Trim(Request.Form("name"))
eEmail = Trim(Request.Form("email))
If Len(eEmail) = 0 then Response.Write "You cannot submit details without submitting your email. Please press the BACK button of your browser and try again."
AllOk = False
End If
If AllOk = True then
bText = "The visitor to the web site has entered the following details:" & Chr(13) & Chr(10) & Chr(13) & Chr(10)
' We use the combination of Chr(13) and Chr(10) to insert the line breaks.
bText = bText & "Visitor's Name: " & nName & Chr(13) & Chr(10) bText = bText & "Visitor's Email: " & eEmail
' This section uses SMTP ' Sending the email to the webmaster.
Set Mailer = Server.CreateObject("SMTPsvg.Mailer) Mailer.FromAddress = eEmail Mailer.FromName = nName Mailer.AddRecipient "Webmaster", "webmaster@yourdomain.com" Mailer.RemoteHost = "mail.yourdomain.com" Mailer.Subject = "Form submitted at your web site!" Mailer.BodyText = bText
If Mailer.SendMail then Response.Redirect "thankyou.html" Else Response.Redirect "error.html" End If
Set Mailer = nothing
' This section uses CDONTS ' Sending the email to the webmaster.
Set Mailer = Server.CreateObject("CDONTS.NewMail") Mailer.From = eEmail Mailer.To = "webmaster@yourdomain.com" Mailer.Subject = Form submitted at your web site!" Mailer.Body = bText
If Mailer.Send then Response.Redirect "thankyou.html" Else Response.Redirect "error.html" End If
Set Mailer = nothing
End If
.%>
I have demonstrated both CDONTS and SMTP, but you have to use only one. You'll have to ask your web host what to use.
As usual, if you have a doubt, you can write to me at amrit@bytesworth.com.
All the best.
About the Author
Amrit Hallan is a freelance web designer. For all web site development and web promotion needs, you can get in touch with him at http://www.bytesworth.com. For more such articles, visit http://www.bytesworth.com/articles and http://www.bytesworth.com/learn You can subscribe to his newsletter [BYTESWORTH REACHOUT] on Web Designing Tips & Tricks by sending a blank email at bytesworth-subscribe@topica.com
|
|
|
|
 |
|
|
| _Additional Resources ... |



|
Beyond Repair: The fixed-price model Don't get me wrong. I certainly don't think the majority of vendors who use a fixed-price model are trying to rip you off. In fact, when I started my business that's the way we worked—which is why we have such great insight into the flaws in the...
Ten Major Tips to Develop a Multilingual Web Site to Work If you are living in a country that its native language is something rather than English language, then you may like to develop your website to offer content in the language of your own country. There are millions of websites on the Internet that...
Legal Music Downloads On July 28, 2004, French Internet access providers and music copyright owners signed a joint national charter aimed at cracking down on illegal downloads and expanding the amount of legal music tracks available online (AFP). This is the latest in a...
|
|
|
|
|
|
 |
|
|
|