<%
Dim objCDONTS ' Email object
Dim strFromName ' From persons' real name
Dim strFromEmail, strToEmail ' Email addresses
Dim strSubject, strBody ' Message
Dim strThisPage ' This page's URL
Dim strReferringPage ' The referring page's URL
Dim bValidInput ' A boolean indicating valid parameters
' Retrieve this page name and referring page name
strThisPage = Request.ServerVariables("SCRIPT_NAME")
strReferringPage = Request.ServerVariables("HTTP_REFERER")
' Debugging lines:
'Response.Write strThisPage & "
" & vbCrLf
'Response.Write strReferringPage & "
" & vbCrLf
' Read in and set the initial values of our message parameters
strFromName = Trim(Request.Form("txtFromName"))
strFromEmail = Trim(Request.Form("txtFromEmail"))
strToEmail = Trim(Request.Form("txtToEmail"))
strSubject = strFromName & " denkt, dass diese Seite interessant ist"
strBody = Trim(Request.Form("txtMessage"))
strText = Trim(Request.Form("txttext"))
' I set the body message to a message that referenced the page the
' user arrived from. This makes it great if you place a link to it
' from your different articles, but can be weird if people link in
' from other web sites.
If strBody = "" Then
If strReferringPage = "" Or InStr(1, strReferringPage, "www.abc-suedwest.de", 1) = 0 Or strReferringPage="http://www.abcsuedwest/navigation/mailpage.asp" Then
strBody = ""
strBody = strBody & "Diesen Link empfehle ich:" & vbCrLf
strBody = strBody & "http://www.abc-suedwest.de" & vbCrLf
strBody = strBody & "__________________________" & vbCrLf
strBody = strBody & "Ergaenzende Nachricht:" & vbCrLf
Else
strBody = ""
strBody = strBody & "Diese Seite im A'B'C Südwest lohnt sich:" & vbCrLf
strBody = strBody & strReferringPage & vbCrLf
strBody = strBody & "__________________________" & vbCrLf
strBody = strBody & "Ergaenzende Nachricht:" & vbCrLf
End If
End If
' Quick validation just to make sure our parameters are somewhat valid
bValidInput = True
bValidInput = bValidInput And strFromName <> ""
bValidInput = bValidInput And IsValidEmail(strFromEmail)
bValidInput = bValidInput And IsValidEmail(strToEmail)
' If valid send email and show thanks, o/w show form
If bValidInput Then
Set Mailer = Server.CreateObject("SMTPsvg.Mailer")
Mailer.FromName = strFromName
Mailer.FromAddress= strFromEmail
Mailer.RemoteHost = "smtp.kundenserver.de"
Mailer.AddRecipient strToEmail, strToEmail
Mailer.Subject = strSubject
Mailer.BodyText = strBody & strText & vbCrLf & vbCrLf & "___________________________________" & vbCrLf & "Ein Service von A'B'C Suedwest (http://www.abc-suedwest.de)" & vbCrLf & "E-Mail: info@abc-suedwest.de"
if Mailer.SendMail then
ShowThanksMsg
else
Response.Write "Fehler: " & Mailer.Response
end if
Else
If "http://" & Request.ServerVariables("HTTP_HOST") & strThisPage = strReferringPage Then
Response.Write "Es gab einen Fehler. Bitte überprüfen Sie Ihre Eingaben:" & "
" & vbCrLf
End If
' Show our information retrieval form
ShowReferralForm strThisPage, strFromName, strFromEmail, strToEmail, strBody
End If
' End of page logic... subs and functions follow!
%>
<%
' Subroutines and Functions that encapsulate some functionality
' and make the above code easier to write... and read.
' A quick email syntax checker. It's not perfect,
' but it's quick and easy and will catch most of
' the bad addresses than people type in.
Function IsValidEmail(strEmail)
Dim bIsValid
bIsValid = True
If Len(strEmail) < 5 Then
bIsValid = False
Else
If Instr(1, strEmail, " ") <> 0 Then
bIsValid = False
Else
If InStr(1, strEmail, "@", 1) < 2 Then
bIsValid = False
Else
If InStrRev(strEmail, ".") < InStr(1, strEmail, "@", 1) + 2 Then
bIsValid = False
End If
End If
End If
End If
IsValidEmail = bIsValid
End Function
' I made this a function just to get it out of the
' logic and make it easier to read. It just shows the
' form that asks for the input
Sub ShowReferralForm(strPageName, strFromName, strFromEmail, strToEmail, strBody)
' I use script_name so users can rename this script without having to change the code.
%>
<%
'The Message to be sent:
'Subject: < %= strSubject % >
'Body: < %= strBody % >
End Sub
' This just shows our thank you message... probably didn't need to
' be a function, but since I made the form one I figured I'd do this
' for consistency.
Sub ShowThanksMsg()
%>
Die Nachricht wurde gesendet. Vielen Dank für das Nutzen dieses Services Ihres A'B'C Südwest
Fenster schließen
(Die Seite, die Sie gesandt haben, taucht dann wieder auf!)
Copyright: A'B'C Südwest 2002
<%
End Sub
%>