<%@ Language=VBScript %> <% Option Explicit ' This basic form processing script is aimed toward people who are not familiar with ASP, ' but allows them to easily edit a few basic settings so they can use it in their site. ' All comments/remarks are preceded by single quotes. ' See the "BEGIN User-configurable settings" section a few lines below this. Dim MailFromName, MailFromEmail, MailTo, MailCC, MailBCC, MailSubject, EmailSuccess, EmailFail, SMTPServer, DisplayEmptyFormEntries Dim BodyHeader, BodyMain Dim ErrorDescription If Request.Form.Count = 0 Then ' There's no point sending the email if nothing was filled in, so display the following error message instead. ' If you want, you can edit the HTML in the "Sub DisplayMailError" subroutine at the end of this file. ErrorDescription = "None of the form fields were filled in." Call DisplayMailError End If ' BEGIN User-configurable settings ' Make sure that your form is using proper HTML syntax or you will run into problems. ' Duplicate or missing field names are a common cause for problems. ' http://www.w3.org/TR/html4/ ' http://www.w3.org/TR/html4/interact/forms.html ' http://validator.w3.org/ ' Feel free to change the following settings. The SMTPServer must be correct. ' The MailFromName (typically a person's name or company name) can be left blank. ' The MailFromEmail is required ' A valid email address must be entered for at least one of these fields: To, CC, BCC ' CC = carbon copy ' BCC = blind carbon copy ' The Subject is obtained from a "Subject" field in the form. Example: ' ' EmailSuccess represents the file you want to display after the mail is successfully sent. ' Name it whatever you want and put anything you want in it. ' EmailFail (if used) represents the file you want to display if the mail is not sent ' (depends on the lines in the ValidateFormData subroutine further below). MailTo = "somevalidemailaddress@whatever.com" MailCC = "" ' Optional: carbon copy MailBCC = "" ' Optional: blind carbon copy (recipients are not displayed in email headers) If InStr(Request.Form("Email"),"@") Then ' If the email field contains an @ symbol (very limited test) assume it's ok to use. MailFromEmail = Request.Form("Email") MailFromName = Request.Form("Name") Else ' If the email field in the form was left blank, make it the same as the "To" address ' and leave the "From name" blank to avoid confusion. MailFromEmail = MailTo MailFromName = "" End If MailSubject = Request.Form("Subject") EmailSuccess = "thanks.htm" ' If the mail was sent, redirect the user to this page to let them know it was sent (change the name to whatever you want). EmailFail = "contactfail.htm" ' This is only relevant if you use the "ValidateFormData" below. DisplayEmptyFormEntries = "no" ' If "yes", blank form entries are displayed in the email. ' Dynamically create the SMTP server name based on the server name in the web site URL. ' E.g.: "www.mydomain.com" and "mydomain.com" get translated to "smtp.mydomain.com". ' If this doesn't work for you, you can replace the line with the following (entering the valid ' SMTP server inside the double-quotes). ' SMTPServer = "" SMTPServer = "smtp." & Replace(Request.ServerVariables("SERVER_NAME"),"www.","") ' Uncomment the "Call ValidateFormData" line if you plan to validate any of the fields in your form ' without using client-side scripting (e.g. JavaScript) on the form itself. If you uncomment this, ' be sure to examine/edit the "Sub ValidateFormData" subroutine below. 'Call ValidateFormData ' END User-configurable settings ' Although the rest of this file is editable/customizeable, you probably won't have a reason to make ' any changes below this point unless you're familiar with ASP. Call CreateMessageBody Call SendEmail Sub ValidateFormData ' Make sure that certain fields are filled out on the form. In the example below, this script ' will not send the mail if any of the following fields (from the form) are empty: ' Email, Name, Phone ' You can customize this or simply comment out the "Call ValidateForm" line to ignore everything ' in the ValidateFormData subroutine if you don't plan on using it. If Request.Form("Email") = "" _ Or Request.Form("Name") = "" _ Or Request.Form("Phone") = "" Then Server.Transfer(EmailFail) Response.End End If End Sub Sub CreateMessageBody ' The BodyHeader reference below is by no means necessary, but it does provide information about ' What form was filled out and when. If you don't want to use it, either comment out the next ' couple of lines or remove the reference to it in the ".TextBody" portion of the "SendEmail" ' subroutine. "vbcrlf" is a carriage return / line feed (creates a new line). BodyHeader = "The following information was retrieved from" & vbcrlf _ & " " & Request.ServerVariables("HTTP_REFERER") & vbcrlf _ & " " & Now() ' Display the field name (from the form) and the value entered. ' This method for displaying the form data is as generic-looking as it gets. Dim i For i = 1 To Request.Form.Count If LCase(DisplayEmptyFormEntries) = "no" And Request.Form.Item(i) = "" Then ' Ignore the empty entry Else ' Display form field name: form field data BodyMain = BodyMain & Request.Form.Key(i) & ": " & Request.Form.Item(i) & vbcrlf End If Next End Sub Sub SendEmail %> <% ' Connect to the mail server and send the mail Dim iMsg, iConf Set iMsg = Server.CreateObject("CDO.Message") Set iConf = iMsg.Configuration ' http://msdn.microsoft.com/library/en-us/cdosys/html/37be0471-06bd-489d-8bf2-5c22bb7ce17c.asp With iConf.Fields .Item(cdoSendUsingMethod) = cdoSendUsingPort ' http://msdn.microsoft.com/library/en-us/cdosys/html/bb2a4e60-080f-49bf-be71-e2a7e52ce5ad.asp .Item(cdoSMTPServer) = SMTPServer ' http://msdn.microsoft.com/library/en-us/cdosys/html/d1c332e6-a675-47be-9c13-8f612169a5d2.asp .Update End With ' http://msdn.microsoft.com/library/en-us/cdosys/html/39186eaa-c4c1-430a-9715-35e291925c5c.asp With iMsg .From = """" & MailFromName & """ <" & MailFromEmail & ">" .To = MailTo .CC = MailCC .BCC = MailBCC .Subject = MailSubject .BodyPart.Charset = "us-ascii" .TextBody = BodyHeader & vbcrlf & vbcrlf & BodyMain On Error Resume Next .Send End With If Err.Number <> 0 Then ErrorDescription = Err.Description End If On Error Goto 0 Set iConf = Nothing Set iMsg = Nothing If ErrorDescription = "" Then Server.Transfer(EmailSuccess) Else Call DisplayMailError End If End Sub Sub DisplayMailError %> Error sending email

Your message was NOT sent:
Error: <%=ErrorDescription%>

<% End Sub %>