Basic CDONTS E-Mail Form w/ASP Validation:
Click here
to test this script.
Code:
default.asp
*
Highlight
<%option explicit%> <% dim emailto dim emailcc dim emailfrom dim emailsubject dim emailbody dim formStr dim error dim errorStr dim smtp if request.form <> "" then emailto = request.form("emailto") emailcc = request.form("emailcc") emailfrom = request.form("emailfrom") emailsubject = request.form("emailsubject") emailbody = request.form("emailbody") formStr = "emailcc=" & emailcc formStr = formStr & "&" & "emailsubject=" & emailsubject formStr = formStr & "&" & "emailbody=" & emailbody formStr = replace(formStr,"&&", "") if emailto = "" then errorStr = "emailto," if emailto <> "" then formStr = formStr & "&emailto=" & emailto if emailfrom = "" then errorStr = "emailfrom," & errorStr if emailfrom <> "" then formStr = formStr & "&emailfrom=" & emailfrom errorStr = replace(errorStr,"&&", "") if errorStr <> "" then errorStr = left(errorStr,(len(errorStr) -1)) response.redirect "default.asp?error=" & errorStr & "&" & formStr end if set smtp = server.createobject("cdonts.newmail") smtp.to = emailto smtp.cc = emailcc smtp.from = emailfrom smtp.subject = emailsubject smtp.body = emailbody smtp.send set smtp = nothing response.redirect "default.asp?email=sent" end if %>
<%if request.querystring("email") = "sent" then%>
Your e-mail has been sent!
<%end if%> <%if instr(request.querystring("error"),"emailto") then%>
Please enter the recipient's e-mail address.
<%end if%> <%if instr(request.querystring("error"),"emailfrom") then%>
Please enter your e-mail address.
<%end if%>
>
To:
value="<%response.write (request.querystring("emailto"))%>">
CC:
">
>
From:
value="<%response.write (request.querystring("emailfrom"))%>">
Subject:
">
Message:
*Un-comment <textarea> input