%@ Language=VBScript %>
<%
'set some constants
Const EMAIL_FROM_ADDRESS = "info@kidzforlife.com"
Const EMAIL_FROM_NAME = "Kidz for Life"
Const EMAIL_RECIPIENT_ADDRESS = "cebplh@yahoo.com, cam@greenhousecreative.net"
Const EMAIL_RECIPIENT_NAME = "Kidz for Life"
Const EMAIL_SUBJECT = "Contact Info from the Website"
Const SMTP_SERVER = "localhost"
' Handle Postback
Dim isPostBack
isPostBack = (request("_postback") <> "")
'set any special fields (not in the form post)
Dim dictSpecialFields
set dictSpecialFields = server.CreateObject("scripting.dictionary")
dictSpecialFields.Add "Date", formatdatetime(now(),vbLongDate) & " " & time()
dictSpecialFields.Add "URL", CurrentURLPath()
function MergeFields(content)
Dim fld, key, newContent, fldValue
newContent = content
'merge form data
for each key in request.Form
fld = "[" & key & "]"
fldValue = request.form(key)
fldValue = server.HTMLEncode(fldValue)
fldValue = replace(fldValue,vbCRLF,"
")
newContent = replace(newContent,fld,fldValue)
next
'merge special fields data
for each key in dictSpecialFields
fld = "[" & key & "]"
fldValue = dictSpecialFields(key)
fldValue = server.HTMLEncode(fldValue)
fldValue = replace(fldValue,vbCRLF,"
")
newContent = replace(newContent,fld,fldValue)
next
MergeFields = newContent
end function
function GetEmailContent(filename)
Dim fs, ts, emailPath, body
emailPath = server.MapPath("./emails") & "\"
set fs = server.CreateObject("scripting.filesystemobject")
set ts = fs.OpenTextFile(emailPath & filename)
body = ts.ReadAll
ts.close
set fs = nothing
set ts = nothing
GetEmailContent = body
end function
function CurrentURLPath()
Dim serverName, url, path, tmp
serverName = request.ServerVariables("SERVER_NAME")
url = request.ServerVariables("URL")
tmp = split(url,"/")
redim preserve tmp(ubound(tmp)-1)
url = join(tmp,"/")
path = "http://" & serverName & url
CurrentURLPath = path
end function
function SendMailASPMail(msg)
Set Mailer = Server.CreateObject("SMTPsvg.Mailer")
Mailer.FromName = EMAIL_FROM_NAME
Mailer.FromAddress= EMAIL_FROM_ADDRESS
Mailer.RemoteHost = SMTP_SERVER
Mailer.AddRecipient EMAIL_RECIPIENT_NAME, EMAIL_RECIPIENT_ADDRESS
Mailer.Subject = EMAIL_SUBJECT
Mailer.BodyText = msg
if Mailer.SendMail then
Response.Write "Mail sent..."
else
Response.Write "Mail send failure. Error was " & Mailer.Response
end if
end function
function sendMailCDO(msg)
Dim cdoMail
Set cdoMail = CreateObject("CDONTS.NewMail")
cdoMail.From = EMAIL_FROM_ADDRESS
cdoMail.To = EMAIL_RECIPIENT_ADDRESS
cdoMail.Subject = EMAIL_SUBJECT
cdoMail.BodyFormat = 0
cdoMail.MailFormat = 0
cdoMail.Body = msg
cdoMail.Send
end function
function sendMailJMail(body)
' mail object
set msg = Server.CreateOBject( "Jmail.message" )
' logging for debugging, silent for errors
msg.Logging = true
msg.silent = true
' sender
msg.Sender = EMAIL_FROM_ADDRESS
msg.SenderName = EMAIL_FROM_NAME
' recipients
msg.AddRecipient EMAIL_RECIPIENT_ADDRESS
' subject
msg.Subject = EMAIL_SUBJECT
'HTML email
msg.Body = "Test"
msg.HTMLBody = body
msg.ContentType = "text/html"
' send message and capture errors
if not msg.Execute then
'Response.write "
" & msg.log & "" else 'Response.write "Message sent successfully!" end if 'close connection 'close everything Set msg = Nothing end function %> <% if isPostBack then Dim body body = GetEmailContent("contact_kfl.htm") body = MergeFields(body) call sendMailCDO(body) end if %>