Form to mail form (.asp). Example 1 , Example 2 , Example 3
This tutorial uses Bamboo.SMTP mail component
If this component is not available in your server try
JMail.SMTP Mail component
If non of them are available contact your server administrator
Example 3

This example is identical to example 2, but in this case we may include a list of emails separated by commas in the form (in "To" field), and an email will be send to each email in the list. 

The form will be the same used in axemple 2 (send_email.html) 

The Form Action must be directed to a diferent page (send-email.asp),

  • In line 1 we must specify the username ("John Smith") and password ("Smith123"). They will be necessary to use this service.
  • In line 13 we must include information related with our server: the IP address or the SMTP Server name (normaly "mail.yoursite.com"). The same information is neccessary in line 36.
  • Lines 32 to 44 are use to send a copy of the email to the sender. They may be remove in order to avoid getting a copy of the message. 
send_email.asp
<% if request.form("username")="John Smith" and request.form("password")="Smith123" then 

message= request.form ("message") & CHR(10) & request.form ("signature")

public emailarray
EmailList=request.form ("emailto")
emailarray=split (EmailList,",")
max=ubound(emailarray)
for counter=0 to max
Wemail=emailarray(counter)

set smtp = Server.CreateObject("Bamboo.SMTP")
smtp.Server = "mail.yoursite.com"
smtp.Rcpt = Wemail
smtp.From = request.form ("emailfrom")
smtp.FromName = request.form ("emailfromname")
smtp.Subject = request.form ("subject")
smtp.Message = message
on error resume next
smtp.Send
if err then
 response.Write ("Internal server error") 
else
 response.Write ("Your message has been delivered successfully.")
end if
set smtp = Nothing

Next

%>

<%

set smtp = Server.CreateObject("Bamboo.SMTP")
smtp.Server = "mail.yoursite.com"
smtp.Rcpt = request.form ("emailfrom")
smtp.From = request.form ("emailfrom")
smtp.FromName = request.form ("emailfromname")
smtp.Subject = "Copy: " & request.form ("subject") 
smtp.Message = message
on error resume next
smtp.Send
set smtp = Nothing
%>

<% else %>
Error: No autorization
<% end If %>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
 
NOTE: You may have problems with this script in your server in case "Bamboo.SMTP" instruction is not supported by your server. In that case you will need a different script. 
 

AspTutorial.info