Sending Form Values to an email
Copy the 2 pages below and paste them into the same folder and then
run form.html on your webserver (this won't work on your personal webserver,
must be an internet server and support the CDONTS mail object).
If you
fill in the text boxes on the form.html page and click submit then the
values entered will be sent to form_ac.asp. Form_ac.asp will be the
page that will receive and process the values entered into the text
boxes.
In our example once the variables have been received by form_ac.asp
an email will then be sent which holds the variables. The comments in
the pages should explain the code.
Call this page form.html
<html>
<head>
<title>form to email script</title>
</head>
<body>
<div align="center">
<form method="POST" action="form_ac.asp" name="form1">
<table width="75%" border="0" cellspacing="0"
cellpadding="0">
<tr>
<td>name:</td>
<td colspan="2">
<input type="text" name="name">
</td>
</tr>
<tr>
<td>email:</td>
<td colspan="2">
<input type="text" name="email">
</td>
</tr>
<tr>
<td>message:</td>
<td colspan="2">
<textarea name="message" cols="40" rows="5"></textarea>
</td>
</tr>
<tr>
<td> </td>
<td colspan="2">
<input type="submit" name="Submit" value="Submit">
<input type="reset" name="Reset" value="Reset">
</td>
</tr>
</table>
</form>
</div>
</body>
</html>
Call this page form_ac.asp (the ac is short for acquire as it will
be receiving values)
<%@ Language="VBscript" %>
<% Option Explicit %>
<html>
<head>
<title>Message Sent</title>
</head>
<body>
<%
Dim name, email, message, NewMailObj
name=request.form("name")
email=request.form("email")
message=request.form("message")
Set NewMailObj=Server.CreateObject("CDONTS.NewMail")
NewMailObj.From = "michael@codefixer.com"
NewMailObj.To = "whoever_you_want_to_send_it_to@hotmail.com"
NewMailObj.Subject = "New message sent.."
NewMailObj.Body = "the name you entered was " & name
& _
"<br>the email was " & email & _
"<br>the message was " & message
NewMailObj.BodyFormat = 0
NewMailObj.MailFormat = 0
NewMailObj.Send
Set NewMailObj = nothing
Response.write "The email was sent."
%>
</body>
</html>
You may be interested in reading our tutorial 'Insert
form content into a database'
Learn how to text format an email
Site developed by Michael Wall - Web Design Belfast N.Ireland.
Copyright © 2000-2008. All rights reserved.
|