%
Dim from_mail, from_name, subject_mail, receivers, use_builtin_host_and_port, smtphost, smtpport, required_fields, email_field, contact_html_pagina, page_to_redirect_after_sending, email_not_valid, required_field_not_valid
' ---------------------------------------------------------------------------------------------------------
' CONFIGZONE: Hier komen de variabele velden in, zoals de ontvangers, het onderwerp van de mail, etc...
from_mail = "webmaster.development@coleurop.be"
from_name = "College of Europe's Development Office"
subject_mail = "Un/Subscribe form DO Newsletter - SHORT"
receivers = Array("jvanloo@coleurop.be")
use_builtin_host_and_port = True 'als dit op true staat wordt er met smtphost en met smtpport geen rekening gehouden, als dit op false staat wordt smtphost en smtpport als smtp server met desbetreffende poort gebruikt
smtphost = "smtp.coleurop.be"
smtpport = 25 'standaardpoort is 25
'required_fields = Array()
required_fields = Array("Name","E-mail")
email_field = "E-mail"
contact_html_pagina = "formmail-DONL-short.html"
page_to_redirect_after_sending = "formmail-DONL-confirmation.html"
email_not_valid = "Email is required"
required_field_not_valid = "#REQUIRED_FIELD# is required"
' END CONFIGZONE
' ---------------------------------------------------------------------------------------------------------
If Len(Request.Form) > 0 Then
'dit is een postback, vang gegevens op en verwerk ze.
Dim isValid, received_values(), contact_html_to_send, fileStream, fileToRead
isValid = True
Set fileStream = Server.CreateObject("Scripting.FileSystemObject")
Set fileToRead = fileStream.OpenTextFile(Server.MapPath(contact_html_pagina), 1)
contact_html_to_send = fileToRead.ReadAll
fileToRead.Close
Set fileToRead = Nothing
Set fileStream = Nothing
Dim formEntryKey, firstTime
firstTime = True
For Each formEntryKey in Request.Form
Dim formEntryValue
formEntryValue = Request.Form(formEntryKey)
If firstTime = True Then
Redim received_values(0)
firstTime = False
Else
Redim PRESERVE received_values(UBound(received_values) + 1)
End If
received_values(UBound(received_values)) = formEntryKey
If formEntryValue = "" And in_array(formEntryKey, required_fields) Then
isValid = False
message_to_popup = Replace(required_field_not_valid, "#REQUIRED_FIELD#", formEntryKey)
End If
If formEntryKey = email_field Then
If formEntryValue = "" And in_array(formEntryKey, required_fields) Then
isValid = False
message_to_popup = Replace(required_field_not_valid, "#REQUIRED_FIELD#", formEntryKey)
Else
Dim regularExpressionObject
Set regularExpressionObject = New RegExp
regularExpressionObject.Pattern = "^[A-Z0-9._-]+@[A-Z0-9][A-Z0-9.-]{0,61}[A-Z0-9]\.[A-Z.]{2,6}$"
regularExpressionObject.IgnoreCase = True
regularExpressionObject.Global = True
If Not regularExpressionObject.Test(formEntryValue) Then
isValid = False
message_to_popup = email_not_valid
End If
Set regularExpressionObject = Nothing
End If
End If
If isValid = False Then
Exit For
End If
contact_html_to_send = Replace(contact_html_to_send, "#" + UCase(formEntryKey) + "#", Replace(formEntryValue, VbCrLf, " ") )
Next
If isValid = True Then
Dim required_field
For Each required_field in required_fields
If Not in_array(required_field, received_values) Then
isValid = False
message_to_popup = Replace(required_field_not_valid, "#REQUIRED_FIELD#", required_field)
Exit For
End If
Next
End If
If isValid = True Then
Dim mail
Set mail = CreateObject("CDO.Message")
If Not use_builtin_host_and_port Then
mail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
mail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = smtphost
mail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = smtpport
mail.Configuration.Fields.Update
End If
mail.From = from_name + " <" + from_mail + ">"
mail.HTMLBody = contact_html_to_send
mail.Subject = subject_mail
Dim receiver, stringTo
stringTo = ""
For Each receiver in receivers
stringTo = stringTo + receiver + ";"
Next
If Len(stringTo) > 1 Then
stringTo = Left(stringTo, Len(stringTo) - 1)
End If
mail.To = stringTo
mail.Send
Set mail = Nothing
Response.Redirect(page_to_redirect_after_sending)
End If
End If
Private Function in_array(stringToSearchFor, arrayToSearchIn)
Dim key, boolToReturn
boolToReturn = False
For Each key in arrayToSearchIn
If stringToSearchFor = key Then
boolToReturn = True
Exit For
End If
Next
in_array = boolToReturn
End Function
%>