02-03-2012

 

Sending email from a web page.

There are probably hundreds of ways of sending email from a webpage. The script shown here works using IIS SMTP mail via a library interface named CDONTS (Collaboration Data Objects for Windows NT). I use this on a Windows 2000 server even though it was created for NT. For more information on CDONTS Click Here

The code below is ASP code. It presents a form to the browser requesting a from address, a to address and a message. When submit is selected, the ASP code makes a call to the CDONTS library to send the email.
The IIS SMTP program then attempts to send the email. The source email address may be checked and validated before the email is sent to ensure, you own the source domain name, this is to prevent SPAM.

 

 <%@ LANGUAGE="VBSCRIPT"%>
<html>
<head>
<title>Test form</title>

</head>
<body>
<%
if ((Request.Form("submit") = "Submit") OR ((Request.Form("submit") = "") and (Request.QueryString("submit") = "y"))) then
Set Mail = CreateObject("CDONTS.NewMail")
Mail.From = Request.Form("address")
Mail.To = Request.Form("destination")
Mail.Subject = "Feedback"
Mail.BodyFormat = "1"
Mail.MailFormat = "1"
Mail.Importance = "1"
Mail.Body = request.servervariables("remote_addr") & vbcrlf & _
Request.Form("name") & vbcrlf & _
vbcrlf & _
Request.Form("message")
Mail.Send
Set Mail = Nothing
%>
Form has been submitted!
<%
else
%>
Contact form <form action="testmail.asp?submit=y" method="post">
<table width="100%" border="0" cellspacing="0" cellpadding="2">
<tr>
<td valign="top">&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td valign="top">Name</td>
<td>
<input class="TEXTFIELD" type="text" name="name">
</td>
</tr>
<tr>
<td valign="top">From Address</td>
<td>
<input class="TEXTFIELD" type="text" name="address">
</td>
</tr>
<tr>
<td valign="top">To Address</td>
<td>
<input class="TEXTFIELD" type="text" name="destination">
</td>
</tr>
<tr>
<td valign="top">&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td valign="top">Message</td>
<td>
<textarea name="message" cols="50" rows="5"></textarea>
</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>
<input type="submit" name="submit" value="Submit">
<input type="reset" name="reset" value="Reset">
</td>
</tr>
</table>
</form>
<%
end if
%>
</body>
</html>

 

This site was last updated 03/02/12