<% ' Validates a visitor inquiry and notifies the PostcardMojo team by email. Class ContactInquiryService_Class Public Function ValidationErrors(name, email, business, message) Dim errs : errs = Array() ReDim errs(-1) If Len(name) = 0 Then AddMessage errs, "Please enter your name." If Len(name) > 100 Then AddMessage errs, "Name must be 100 characters or fewer." If Len(email) = 0 Then AddMessage errs, "Please enter your email address." ElseIf Len(email) > 150 Or Not IsValidEmail(email) Then AddMessage errs, "Please enter a valid email address." End If If Len(business) > 150 Then AddMessage errs, "Business name must be 150 characters or fewer." If Len(message) > 2000 Then AddMessage errs, "Message must be 2000 characters or fewer." ValidationErrors = errs End Function Public Function Notify(name, email, phone, business, message) Dim recipient, smtpServer, smtpPort, smtpUser, body recipient = Setting("ContactRecipient", "covington.daniel@gmail.com") smtpServer = Setting("SmtpServer", "localhost") smtpPort = Setting("SmtpPort", "25") smtpUser = Setting("SmtpUsername", "") body = "New PostcardMojo website inquiry" & vbCrLf & vbCrLf & _ "Name: " & name & vbCrLf & _ "Email: " & email & vbCrLf & _ "Phone: " & phone & vbCrLf & _ "Business: " & business & vbCrLf & vbCrLf & _ "Message:" & vbCrLf & message & vbCrLf & vbCrLf & _ "Received: " & Now() & vbCrLf & _ "IP: " & Request.ServerVariables("REMOTE_ADDR") CDOEmail.From = Setting("SmtpFrom", Choice(Len(smtpUser) > 0, smtpUser, recipient)) CDOEmail.Subject = "PostcardMojo inquiry from " & StripLineBreaks(name) CDOEmail.Body = body CDOEmail.IsBodyHTML = False CDOEmail.SMTPServer = smtpServer CDOEmail.SMTPPort = CLng(smtpPort) CDOEmail.SMTPUsername = smtpUser CDOEmail.SMTPPassword = EnvService().Value("SMTP_PASSWORD", "") CDOEmail.SMTPUseSSL = (LCase(Setting("SmtpUseSsl", "false")) = "true") CDOEmail.AddRecipient "TO", recipient Notify = CDOEmail.Send() End Function Public Function StripLineBreaks(value) StripLineBreaks = Replace(Replace(value, vbCr, " "), vbLf, " ") End Function Private Function Setting(key, fallback) Dim value : value = GetAppSetting(key) If value = "nothing" Or Len(value) = 0 Then value = fallback Setting = value End Function Private Function IsValidEmail(value) Dim re : Set re = New RegExp re.Pattern = "^[^\s@<>,;""]+@[^\s@<>,;""]+\.[A-Za-z]{2,}$" IsValidEmail = re.Test(value) End Function Private Sub AddMessage(ByRef errs, msg) ReDim Preserve errs(UBound(errs) + 1) errs(UBound(errs)) = msg End Sub End Class Dim ContactInquiryService_Class__Singleton Function ContactInquiryService() If IsEmpty(ContactInquiryService_Class__Singleton) Then Set ContactInquiryService_Class__Singleton = New ContactInquiryService_Class End If Set ContactInquiryService = ContactInquiryService_Class__Singleton End Function %>