Replies Back to Article
send a form by email using ASP
Depending on your server type, you can use CDONTS or CDOSYS (newest) to send the e-mail. Below is the code that I use most frequently.
<%
Dim objMail
'//Rename this to the name of your button
If (Request.Form("newuserbtn") <> "") Then
Set objMail = Server.CreateObject("CDONTS.NewMail")
'Collecting form information
email = Request.Form("username")
password = Request.Form("password")
fname = Request.Form("firstname")
lname = Request.Form("lastname")
company = Request.Form("company")
title = Request.Form("title")
phone = Request.Form("phone")
address = Request.Form("address")
city = Request.Form("city")
state = Request.Form("state")
zipcode = Request.Form("zipcode")
country = Request.Form("country")
website = Request.Form("website")
regdate = Request.Form("registerdate")
'Build message body
BodyString = BodyString & "The following user has requested access to www.xxxx.com." & VbCrLf
BodyString = BodyString & "They registered on " & regdate & "." & VbCrLf
BodyString = BodyString & "" & VbCrLf
BodyString = BodyString & "Username: = " & email & VbCrLf
BodyString = BodyString & "Password: = " & password & VbCrLf
BodyString = BodyString & "First Name: = " & fname & VbCrLf
BodyString = BodyString & "Last Name: = " & lname & VbCrLf
BodyString = BodyString & "Company: = " & company & VbCrLf
BodyString = BodyString & "Title: = " & title & VbCrLf
BodyString = BodyString & "Phone: = " & phone & VbCrLf
BodyString = BodyString & "Address: = " & address & VbCrLf
BodyString = BodyString & "City: = " & city & VbCrLf
BodyString = BodyString & "State: = " & state & VbCrLf
BodyString = BodyString & "Zip Code: = " & zipcode & VbCrLf
BodyString = BodyString & "Country: = " & country & VbCrLf
BodyString = BodyString & "" & VbCrLf
objMail.From = email
objMail.Subject = "E-mail Subject Title"
objMail.To = "xxxx@xxxx.com"
objMail.Body = BodyString
objMail.Send
Set objMail = nothing
'Response.Write("We have received your information request, we will be mailing it to you shortly. Thank you!")
End If
%>
I have been looking for code that would send a simple HTML Form via email and I thought I had it with this code, but it didn't work first tiime around.
What went wrong?
<%
Dim objMail
'//Rename this to the name of your button
If (Request.Form("reservation") <> "") Then
Set objMail = Server.CreateObject("CDONTS.NewMail")
'Collecting form information
FirstName = Request.Form("F_Name")
LastName = Request.Form("L_Name")
Address1 = Request.Form("Add_1")
Address2 = Request.Form("Add_2")
City = Request.Form("City")
State = Request.Form("State")
Zip = Request.Form("Zip")
Email = Request.Form("Email")
Phone = Request.Form("Phn")
'Build message body
BodyString = BodyString & "The following user has requested access to www.xxxx.com." & VbCrLf
BodyString = BodyString & "" & VbCrLf
BodyString = BodyString & "First Name: = " & F_Name & VbCrLf
BodyString = BodyString & "Last Name: = " & L_Name & VbCrLf
BodyString = BodyString & "Address1: = " & Add_1 & VbCrLf
BodyString = BodyString & "Address2: = " & Add_2 & VbCrLf
BodyString = BodyString & "City: = " & City & VbCrLf
BodyString = BodyString & "State: = " & State & VbCrLf
BodyString = BodyString & "Zip: = " & Zip & VbCrLf
BodyString = BodyString & "Email: = " & Email & VbCrLf
BodyString = BodyString & "Phone: = " & Phn & VbCrLf
BodyString = BodyString & "" & VbCrLf
objMail.From = email
objMail.Subject = "Test form"
objMail.To = "samsel@comcast.net"
objMail.Body = BodyString
objMail.Send
Set objMail = nothing
'Response.Write("We have received your information request, we will be mailing it to you shortly. Thank you!")
End If
%>
I have the HTML/FORM page action="post" "thankyou.asp"
Let me know - Thanks
Hi
Does this code support also cdosys or is it just cdonts?
If not, how would it be changed to cdosys?
I'm having hard times with cdosys and I would need some help on this.
Cheers
hI
I wanted to ask something.First of all i would like to get the html code in dreamweaver in order to be able to send an email using dreamweaver asp.net
Secondly how does it work?Do i have to choose a server where it supports asp.net in order to preview the project?
thanks please let me know