Send E-mail via ASP

Category:
ASP, HTML and XML
Type:
Modules
Difficulty:
Intermediate
Author:
Valentin G Frixione

Version Compatibility: ASP

More information:
This code shows you how to send SMTP e-mail from an .ASP page. Windows NT Server, Option Pack 4.0 with SMTP services must be installed on the host machine.

The HTML is for illustration purposes, to demonstrate how to use the module.

Instructions: Copy the declarations and code below and paste directly into your VB project.

Declarations:

Code:

Other:

<% '************************************************************ ' SENDFORM.ASP -- Simple Form E-mail Component for ASP ' Created 7/31/98 ' by Valentin Frixione ' e-mail: vfrixion@ix.netcom.com ' -- Must have Microsoft Windows NT 4 Server ' -- running Option Pack 4, with IIS4 & simple SMTP server '************************************************************ If Request.Form("Submit")= "Send Form" then Set objSend = Server.CreateObject("CDONTS.Newmail") objSend.From = Request ("From") objSend.To = Request ("EmailTo") objSend.Subject = Request ("Subject") '-------------------------------------------------- ' Putting the Body of the e-mail together... '-------------------------------------------------- strBodyHeader= "This form was sent via e-mail on " _ & Now & ". " & "

" '---------------------------------------------------------------'Collecting the fields from the HTML Form '-------------------------------------------------------------- strBody ="" For each item in Request.Form if item <> "Submit" then strLineItem = item &" : " & _ Request.Form(item) & "
" strBody = strBody & strLineItem end if Next strBody = strBodyHeader & strBody objSend.Body = strBody '-------------------------------------------------- 'Sending the Form '-------------------------------------------------- objSend.Send If err.number = 0 then 'OK? Response.Write "

" Response.Write "Your message was sent. " response.write "It was:

" & strBody else 'Not OK! Response.Write "

A problem was detected, please " Response.Write "contact the Webmaster with the following " Response.Write "error description.
" Response.Write "Error: " & objSend.Response End if set objSend = Nothing End If %> remove end comment and comment on top before using -->