i have a cgi file that runs a form on my webpage to email me info from the form. Problem is that something is wrong with the setup. I have following fields on form on my webpage: name, phone, email, address, city, state, zip, invest_amt, how_soon, how_found_site, and EmailBody. The form works well, and it emails me the info, but it is not in the right order and i really can't tell from the code how to fix it. I also wanted to put text to let me know what was what when i got the email. Can anyone help? Here's code:
<%@ Language=VBScript %>
<%
' configuration:
mailserver = "mail.mywebsite.com" ' Type in the name of the SMTP mail server of
' your server here
recipient = "info@mywebsite.com" ' Type your email address here
redirect = " ' Type in the name of the page to appear after
' the email has been sent
' build particulars
method = Request.ServerVariables("HTTP_METHOD")
Subject = Request("Subject")
fromemail = Request("email")
fromname = Request("username")
excludeflds = split(Request("exclude"),",")
' set defaults if not specified
if subject = "" then
Subject = "Email from my WebSite" ' If the user leaves the subject blank then
end if ' you can specify a default subject
if fromemail = "" then
fromemail = "anonymous@yahoo.com" ' If the user leaves the email address field
end if 'blank then you can specify a default address
if fromname = "" then
fromname = "Anonymous" ' If the user leaves the name field blank then
end if ' you can specify a default name
' determine the method of the form (post or get)
select case lcase(method)
case "post"
'build a delimited list of the field names
for each fld in Request.Form
' remove the fieldnames of the email configuration fields
select case lcase(fld)
case "exclude","email","subject","recipient","redirect","mailserver","username"
' do nothing
case else
tmpfldnames = tmpfldnames & fld & ","
end select
next
case "get"
'build a delimited list of the field names
for each fld in Request.QueryString
' remove the fieldnames of the email configuration fields
select case fld
case "exclude","email","subject","recipient","username"
' do nothing
case else
tmpfldnames = tmpfldnames & fld & ","
end select
next
end select
' remove the trailing comma
if mid(tmpfldnames,len(tmpfldnames),1) = "," then
tmpfldnames = mid(tmpfldnames,1,len(tmpfldnames)-1)
end if
' build an array of the fieldnames
fldarray = split(tmpfldnames,",")
' build the message header
bodytext = "<Date sent> " & now() ' Specify a header for the email body
bodytext = bodytext & invest_amt & how_soon & how_found_site & vbcrlf
' cycle through all of the fields
for each fld in fldarray
PrintFld = True
' exclude fields in the exclude list
for each checkfld in excludeflds
if trim(lcase(checkfld)) = trim(lcase(fld)) then
PrintFld = False
end if
next
' continue building the mail message with the form results
if PrintFld = True then
bodytext = bodytext & "<" & fld & "> " & request(fld) & vbcrlf ' Formatting for individual fields being inserted
end if
next
sentbin = sendmail(mailserver,fromname,fromemail,recipient,subject,bodytext)
select case sentbin
case true ' If no problems then the redirect page is loaded
Response.Redirect(redirect)
case false ' Otherwise an error is raised and the message is displayed
Response.write("<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.0 Transitional//EN'><html><head><title>Error sending email...</title></head><body>")
Response.write("<!--#include file='errorhdr.html'-->") ' Use this line to display a header
Response.write("<font face='arial' size='2'>There was a problem sending the email... <br><br>Please hit the back button in your browser and try again.</font>")
Response.write("<!--#include file='errorftr.html'-->") ' Use this line to display a footer
Response.write("</body></html>")
end select
' This function actually sends the mail using ASPMail and returns true if the mail was sent
' - returns false if there was an error
Function sendmail(strservername,strfromname,strfromaddress,strRecip,strSub,strBodyText)
Set Mailer = Server.CreateObject("SMTPsvg.Mailer")
'Use one of the following objects depending on which one is installed on the server.
'If you use the second one then you must change the "Mailer" object to "NewMail"
'Do not contact me with problems that refer to line 89 or the line that creates the
'mail, because I can not install server objects and software for you - you must do that!
'Otherwise, feel free to contact me.
'Set Mailer = Server.CreateObject("CDONTS.NewMail")
Mailer.FromName= strfromname
Mailer.FromAddress= strfromaddress
Mailer.RemoteHost = strservername
Mailer.AddRecipient strrecip, strrecip
Mailer.Subject= strSub
Mailer.BodyText= strBodyText
if Mailer.SendMail then
sendmail = true
else
sendmail = false
end if
end function
%>
<%@ Language=VBScript %>
<%
' configuration:
mailserver = "mail.mywebsite.com" ' Type in the name of the SMTP mail server of
' your server here
recipient = "info@mywebsite.com" ' Type your email address here
redirect = " ' Type in the name of the page to appear after
' the email has been sent
' build particulars
method = Request.ServerVariables("HTTP_METHOD")
Subject = Request("Subject")
fromemail = Request("email")
fromname = Request("username")
excludeflds = split(Request("exclude"),",")
' set defaults if not specified
if subject = "" then
Subject = "Email from my WebSite" ' If the user leaves the subject blank then
end if ' you can specify a default subject
if fromemail = "" then
fromemail = "anonymous@yahoo.com" ' If the user leaves the email address field
end if 'blank then you can specify a default address
if fromname = "" then
fromname = "Anonymous" ' If the user leaves the name field blank then
end if ' you can specify a default name
' determine the method of the form (post or get)
select case lcase(method)
case "post"
'build a delimited list of the field names
for each fld in Request.Form
' remove the fieldnames of the email configuration fields
select case lcase(fld)
case "exclude","email","subject","recipient","redirect","mailserver","username"
' do nothing
case else
tmpfldnames = tmpfldnames & fld & ","
end select
next
case "get"
'build a delimited list of the field names
for each fld in Request.QueryString
' remove the fieldnames of the email configuration fields
select case fld
case "exclude","email","subject","recipient","username"
' do nothing
case else
tmpfldnames = tmpfldnames & fld & ","
end select
next
end select
' remove the trailing comma
if mid(tmpfldnames,len(tmpfldnames),1) = "," then
tmpfldnames = mid(tmpfldnames,1,len(tmpfldnames)-1)
end if
' build an array of the fieldnames
fldarray = split(tmpfldnames,",")
' build the message header
bodytext = "<Date sent> " & now() ' Specify a header for the email body
bodytext = bodytext & invest_amt & how_soon & how_found_site & vbcrlf
' cycle through all of the fields
for each fld in fldarray
PrintFld = True
' exclude fields in the exclude list
for each checkfld in excludeflds
if trim(lcase(checkfld)) = trim(lcase(fld)) then
PrintFld = False
end if
next
' continue building the mail message with the form results
if PrintFld = True then
bodytext = bodytext & "<" & fld & "> " & request(fld) & vbcrlf ' Formatting for individual fields being inserted
end if
next
sentbin = sendmail(mailserver,fromname,fromemail,recipient,subject,bodytext)
select case sentbin
case true ' If no problems then the redirect page is loaded
Response.Redirect(redirect)
case false ' Otherwise an error is raised and the message is displayed
Response.write("<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.0 Transitional//EN'><html><head><title>Error sending email...</title></head><body>")
Response.write("<!--#include file='errorhdr.html'-->") ' Use this line to display a header
Response.write("<font face='arial' size='2'>There was a problem sending the email... <br><br>Please hit the back button in your browser and try again.</font>")
Response.write("<!--#include file='errorftr.html'-->") ' Use this line to display a footer
Response.write("</body></html>")
end select
' This function actually sends the mail using ASPMail and returns true if the mail was sent
' - returns false if there was an error
Function sendmail(strservername,strfromname,strfromaddress,strRecip,strSub,strBodyText)
Set Mailer = Server.CreateObject("SMTPsvg.Mailer")
'Use one of the following objects depending on which one is installed on the server.
'If you use the second one then you must change the "Mailer" object to "NewMail"
'Do not contact me with problems that refer to line 89 or the line that creates the
'mail, because I can not install server objects and software for you - you must do that!
'Otherwise, feel free to contact me.
'Set Mailer = Server.CreateObject("CDONTS.NewMail")
Mailer.FromName= strfromname
Mailer.FromAddress= strfromaddress
Mailer.RemoteHost = strservername
Mailer.AddRecipient strrecip, strrecip
Mailer.Subject= strSub
Mailer.BodyText= strBodyText
if Mailer.SendMail then
sendmail = true
else
sendmail = false
end if
end function
%>