<%@ Language=VBScript %> <% 'option explicit %> <% Set myMail = createobject("cdo.Message") Set myMailConfig = createobject("cdo.configuration") 'Setting the SMTP Server Set Flds = myMailConfig.Fields Set myMail.Configuration = myMailConfig dim lastname dim firstname dim comments dim tel dim email dim msg dim letters dim eletters dim continueProcessing dim arrVarsToCheck dim arrVars dim VarCount letters = "abcdefghijklmnopqrstuvwxyz" eletters = "abcdefghijklmnopqrstuvwxyz0123456789.@-_" continueProcessing = True function isNullString(s) isNullString = len(s) = 0 end function function checkLength(s, minLength) checkLength = len(s) >= minLength end function function isAlpha(aChar) isAlpha = instr(1, letters, aChar, vbTextCompare) > 0 end function function isEmailAlpha(aChar) isEmailAlpha = instr(1, eletters, aChar, vbTextCompare) > 0 end function function allAlpha(s) dim i for i = 1 to len(s) if not isalpha(mid(s,i,1)) then exit function end if next allAlpha = true end function function allEmailAlpha(s) dim i for i = 1 to len(s) if not isEmailAlpha(mid(s,i,1)) then exit function end if next allEmailAlpha = true end function function checkTelChars(s) dim telChars dim containsExt dim hasExt dim aPos dim i telChars = "0123456789()- ext" for i = 1 to len(s) aPos = instr(1, telChars, mid(s, i, 1), vbTextCompare) if aPos = 0 then ' invalid character exit function elseif aPos > 14 then hasExt = true end if next if hasExt then if not ((s like ("* x*")) or (s like ("* ext*"))) then exit function end if end if checkTelChars = True end function function countDigits(s) dim digits dim i digits = "0123456789" for i = 1 to len(s) if instr(1, digits, mid(s, i, 1), vbTextcompare) > 0 then countDigits = countDigits + 1 end if next end function function checkVars(varNames, vars) dim i for i = 0 to ubound(varNames) select case varNames(i) case "FirstName", "LastName" if len(trim(vars(i))) = 0 then msg = "You must enter a " & varNames(i) & "." exit function end if if not checkLength(vars(i), 2) then msg = "You have entered an invalid " & varNames(i) & " (minimum 2 characters)." exit function end if if not allAlpha(vars(i)) then msg = "The " & varNames(i) & " you entered contains invalid characters." end if case "Comments" if not checkLength(vars(i), 1) then msg = "You must enter a comment." exit function end if case "Telephone" if not checkTelChars(vars(i)) then msg = "The telephone number you entered contains invalid characters." exit function end if if countDigits(vars(i)) < 10 then msg = "You must enter the area code and your 7-digit telephone number." exit function end if case "Email" if len(trim(vars(i))) = 0 then msg = "You must enter a valid" & varNames(i) & "." exit function end if if not checkLength(vars(i), 6) then msg = "You have entered an invalid " & varNames(i) & " (minimum 7 characters)." exit function end if if not allEmailAlpha(vars(i)) then msg = "The " & varNames(i) & " you entered contains invalid characters." exit function end if if instr(email, "@") <> 0 then else msg = "The " & varNames(i) & " you entered is not a valid email." end if if instr(email, ".") <> 0 then else msg = "The " & varNames(i) & " you entered is not a valid email." end if end select next end function if Request("Submit") = "Submit" then lastname = Request("LastName") lastname = Trim(lastname) firstname = Request("FirstName") firstname = Trim(firstname) comments = Request("Comments") comments = trim(comments) email = Request("Email") email = trim(email) tel = Request("Telephone") tel = trim(tel) arrVars = Array(firstname, lastname, comments, tel, email) arrVarsToCheck = Array("FirstName", "LastName", "Comments", "Telephone", "Email") call checkVars(arrVarsToCheck, arrVars) if len(msg) > 0 then ' user did not fill out the form properly else Flds.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 Flds.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "localhost" Flds.update myMail.Subject="Message from the Email Form" myMail.From = email myMail.To = "Rob@007computer.com" myMail.TextBody = "Here is the message sent from:"&VbCrLf&firstname&" "&lastname&" "&tel&VbCrLf&comments myMail.fields.update myMail.Send set myMail=nothing set myMailConfig=nothing %> iRobertFowler.com
www.iRobertFowler.com




Thank you <% response.write(firstname & " " & lastname ) %> for filling out the form!

on

<% dim IPAddr IPAddr = Request.ServerVariables("remote_addr") Response.Write("Your IP Address is " & IPAddr) ' IPAddr = Request.ServerVariables("remote_host") ' Response.Write("Your IP Address is " & IPAddr) %>

<% response.end end if end if %> iRobertFowler.com
www.iRobertFowler.com