This page is related to sending form mail using a GoDaddy account, but most of this data can be used at other ISP's.
GoDaddy's example script
<
from = request.form("from")
email = request.form("to")
body = request.form("body")
subject = request.form("subject")
>
<
Dim objMail
Set objMail = Server.CreateObject("CDONTS.NewMail")
objMail.From = from
objMail.Subject = subject
objMail.To = email
objMail.Body = body
objMail.Send
Response.redirect "thankyou.asp" <- auto-redirection
'You must always do this with CDONTS.
Set objMail = Nothing
>
|
<% .. %> not < .. >
<%
from = request.form("from")
body = request.form("body")
subject = request.form("subject")
body = "From: " & from & vbCRLF & vbCRLF & body
Dim objMail
Set objMail = Server.CreateObject("CDONTS.NewMail")
objMail.To = "YourEmail@somewhere.com" ' hardcode this
objMail.From = "dummyAddress@abc.com" ' hardcode this
objMail.Subject = subject
objMail.Body = body
objMail.Send
Response.redirect "thankyou.asp" ' <- auto-redirection
'You must always do this with CDONTS.
Set objMail = Nothing
%>
|
CDONTS.NewMail Object
The properties to, cc, and bcc each allow you to include one or more email addresses - multiple addresses are separated by semicolons.
objMail.To = "useraddress@example.com" objMail.To = "user1@example.com;user2@example.com;user3@example.com" |
objMail.From = "useraddress@example.com" ' good objMail.From = "Just any text" ' fails - not a valid address objMail.From = "user1@example.com;user2@example.com" ' fails - semicolon not allowed |
CDONTS_MailForm.asp
<%
' CDONTS_MailForm.asp
'
' 02-13-08 started - by R Clemenzi
'
' This only works with "post" html forms
' read form variables
from = request.form("FromAddress")' optional field
body = request.form("body") ' what the person types
subject = request.form("subject") ' from a hidden field
redirect = request.form("redirect") ' from a hidden field
from_url = request.form("a_url") ' from a hidden field
ref_url = request.form("ref_url") ' from a hidden field
value = request.form("val") ' from a hidden field - spam protection
if value <> "pen" then Response.redirect "404_NotFound.html" ' quit if invalid submission
if subject = "" then subject = "[mc-computing] null subject"
if from <> "" then body = "From: " & from & vbCRLF & vbCRLF & body
body = body & vbCRLF & vbCRLF & "url: " & from_url
body = body & vbCRLF & vbCRLF & "url: " & ref_url
' send the email
Dim objMail
Set objMail = Server.CreateObject("CDONTS.NewMail")
objMail.To = "someone@anywhere.com" ' always hard code this to hide from spammers
objMail.From = "dummy_address@xx.com" ' too hard to validate
objMail.Subject = subject
objMail.Body = body
objMail.Send
Set objMail = Nothing 'You must always do this with CDONTS
if redirect = "" then redirect = "Feedback_Done.html"
Response.redirect redirect ' next page the user sees
%>
|
objMail.To
objMail.To = "someone@anywhere.com" ' always hard code this to hide from spammers |
objMail.From
In addition, the "rules" are not published on the Microsoft web site ... except to say that semicolons are not allowed.
As a result, I decided to simply hardcode a "valid" (but fake) address and to include what the user typed in the body of the message.
objMail.From = "dummy_address@xx.com" ' too hard to validate |
The following code reads what the user typed and, if it is not blank, simply adds it to the beginning of the message.
from = request.form("FromAddress") ' optional field
if from <> "" then body = "From: " & from & vbCRLF & vbCRLF & body
|
Spam Protection
value = request.form("val") ' from a hidden field - spam protection
if value <> "pen" then Response.redirect "404_NotFound.html" ' quit if invalid submission
|
The following all produce - HTTP 500 - Internal server error
if value <> "pen" then return if value <> "pen" then request.end if value <> "pen" then exit if value <> "pen" then exit sub if value <> "pen" then Server.Transfer "404_NotFound.html" |
Therefore I decided to use the following which produces - Page Not Found
if value <> "pen" then Response.redirect "404_NotFound.html" |
In addition, you should use a unique filename for this script - perhaps, just add your initials - so that it is harder for spammers to hit lots of accounts.
Sending Attachments
Advantages
<textarea name="body" cols="70" rows="20"></textarea> |
Set objMail = Server.CreateObject("CDONTS.NewMail")
objMail.Body = body
|
Set objMail = Server.CreateObject("CDO.Message")
objMail.TextBody = body
|
IIS 7
| NOTE: This script will not work on Windows® hosting plans running IIS 7. |
| WARNING: As of October 29th, 2008, gdform.asp is no longer offered on Windows shared hosting accounts. If your account does not have gdform.asp, these instructions will not work. |