|
Receiving email from your web page
is a common task. In addition you can also hide your email address, partially hiding your address from spam generators.
Then
you can also put an option for a visual word check to further prevent
spamming , which is discusses in aspnet email forms.
Asp email form.
Here we are using a form to capture
the email, subject and message from the browser. Then we are
checking if any field is empty or not. If every thing is ok, we are
calling our email function to send the email. The email function can
be written in number of ways, we are using cdosys here.
<%
pagename="testemail.asp"
ownersEmail="me@hotmail.com" ' site
owners email address.
If request("B1")<>"" Then
If request("subject")="" Then
Response.write "Please enter a subject<br>"
ElseIf request("message")="" Then
Response.write "Please enter some message<br>"
ElseIf request("email")="" Then
Response.write "Senders email address is required.<br>"
Else
'Send Email
Dim Result
fromEmail=request("email")
Subject=request("subject")
Message=request("message")
Result=SendMail(ownersEmail, subject, message, fromEmail)
If Result="" Then
Response.write "Email Sent.<br>"
Else
Response.write "Error Happened:" & Result & "<br>"
End If
End If
End if
Function
SendMail(toEmail, subject, body, fromEmail)
On Error resume next
Dim iMsg
Set iMsg = CreateObject("CDO.Message")
Dim iConf
Set iConf = CreateObject("CDO.Configuration")
Dim Flds
Set Flds = iConf.Fields
Flds("http://schemas.microsoft.com/cdo/configuration/sendusing")
= 1
Flds("http://schemas.microsoft.com/cdo/configuration/smtpserverpickupdirectory")
= "c:\inetpub\mailroot\pickup"
Flds.Update
Set iMsg.Configuration = iConf
iMsg.To = toEmail
iMsg.From = fromEmail
iMsg.Subject = subject
iMsg.TextBody = body
iMsg.Send
If Err.number > 0 then
Set smtp = " ERROR : " &Err.number & " - > " &
Err.description
else
SendMail = ""
End If
End Function
%>
<form method="POST" action=<%=pagename%>>
Email<br>
<input type="text" name="email" size="20"><br>
Subject<br>
<input type="text" name="subject" size="20"><br>
Message<br>
<textarea rows="8" name="message" cols="30"></textarea><br>
<br>
<input type="submit" value="Submit" name="B1">
<input type="reset" value="Reset" name="B2">
</form>
|
[Download
Sample Code]
|