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 2

This script will allow us to send emails form our server while we are working online. Additionaly, we may set up in advance the content of our email (or at least a primary content). 

First of all you need a form, as for example the one in the table. It will look like this one.
 

  • In order to avoid non-autorized persons to use this page a user name and a password must be introduce when sending a email.
  • We may set up in advance the name of the person sending the email and the email (John@Smith.com in line 12 and John Smith in line 13). 
  • We may set up the content of the email in advance (lines 28 to 24) and the signature (lines 29 and 30). Both, content and signature may be change when filling the form.
send_email.html
<html>
<head><title>Send email</title></head>
<body bgcolor=FFFFFF>

<form method=post action=send_email.asp>
<table border=0>
<tr><td><b>Autentification</b></td><td></td></tr>
<tr><td>Username: </td><td><input type=text name=username size=30></td></tr>
<tr><td>Password: </td><td><input type=password name=password size=30></td></tr>
<tr><td><b>Email</b></td><td></td></tr>
<tr><td>To: </td><td><input type=text name=emailto size=40></td></tr>
<tr><td>From:</td><td><input type=text name=emailfrom size=40 value=John@Smith.com></td></tr>
<tr><td>FromName:</td><td><input type=text name=emailfromname size=40 value="John Smith"></td></tr>
<tr><td>Subject:</td><td><input type=text name=subject size=40></td></tr>
</table>
Your message:<BR>
<textarea name=message rows=14 Cols=80>

Dear Sir/Madam,

I will meet you at the airport tomorrow morning

Take care,

</textarea><BR>
Signature<BR>
<textarea name=signature rows=7 Cols=80>

John Smith
Marketing Director

</textarea><BR>
<input type=submit value="Send email">
</form>

</body></html>

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

The Form Action must be directed to the ASP script bellow.

  • In line 1 we must specify the username (" John Smith") and password ("Smith123"). They will be necessary to use this service (just to avoid someone else to use it).
  • In line 6 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 25.
  • Lines 24 to 34 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")

set smtp = Server.CreateObject("Bamboo.SMTP")
smtp.Server = "mail.yoursite.com"
smtp.Rcpt = request.form ("emailto")
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
%>

<%

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
 
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.