%Option Explicit 'Global result string Dim g_sResult ' // This function sends a mail using the "CDONTS" object Public Function SendMail(ByVal sSubject, ByVal sMessage, _ ByVal sSender, ByVal sRecipients, _ ByVal iFormat) ' Handle errors ourselves on Error resume next Err.Clear Dim objEmail ' Stores Mailer instance Set objEmail = Server.CreateObject("Dundas.Mailer") ' Mail object objEmail.Tos.Add sRecipients objEmail.FromAddress = sSender objEmail.Subject = sSubject objEmail.SMTPRelayServers.add "smtp.keitonengineering.co.uk" objEmail.SMTPRelayServers.Add "smtp.keitonengineering.co.uk" if iFormat = 0 Then objEmail.Body = sMessage Else objEmail.BodyHTML = sMessage End If objEmail.SendMail if err.Number <> 0 Then SendMail = "The following Error occured: " & Err.Description Else SendMail = "The Email was successfully forwarded to the specified SMTP Server" End If Set objEmail = Nothing End Function ' // This will be our entry level function. '// It tests to see if an email address was specified, if so then all form fields are concatenated into the '// sMessage string and sent to the SendMail function. Public Function Main() Dim sMessage, i, fld If Request("email") <> "" Then ' Loop through each field in the form we are sent and make it into one long message for each fld in Request.Form if sMessage = "" Then sMessage = fld & " = " & Request.Form(fld) Else sMessage = sMessage & vbcrlf & fld & " = " & Request.Form(fld) End If Next ' Now we have our total message, send it to the email address supplied: ' Request("email") ' And make it from ash.mahmood@tic.ac.uk g_sResult = SendMail("Test Mail", sMessage, "ash.mahmood@tic.ac.uk", _ Request("email"), 0) End IF End Function '// Enter Program Call Main() %>
|