ASP form to email

message from beckiehawk on 16 Jul 2004
HELP! I found (what I thought was) a really cool form to email ASP it does
everything I need it to do EXCEPT send me the email. Can someone look at it
and tell me what I'm doing wrong, please.

The form is at www.imagineadv.com/customer_resources/4-page_order.asp
The asp is at www.imagineadv.com/customer_resources/formmail.asp

Thanks for your help!
 
christoff915 replied to beckiehawk on 16 Jul 2004
www.kaosweaver.com

you can find kaos mailer here, which is a dreamweaver extension that will
create the asp page for you. you just have to design the form and then assign
kaos mailer to the form and it takes care of everything else, for the most
part. it's very easy to use, and it's free.
as for your code, i'm just learning asp myself, so i'm not going to try to
give you advice on manual coding. i wouldn't want to give you bad advice. there
are much more knowledgable people here than i. i'll let them field the actual
code.

give kaos mailer a try though, it works and you can always look at the code it
generates and compare it to your own.

hope it helps,
christoff
 
Les Matthews replied to beckiehawk on 16 Jul 2004
You will have to supply the asp code that is supposed to generate the email
before anyone can help. Going to the page with a browser only shows the
rendered html.
What is the mail component - CDONTS, CDO, ASPMail?
Have you checked to ensure smtp is running on the server?

"beckiehawk" <webforumsuser@macromedia.com> wrote in message
news:cd8ssg$qou$1@forums.macromedia.com...
 
beckiehawk replied to Les Matthews on 16 Jul 2004
<%@ LANGUAGE="VBScript" %>
<% '***************************************************************************
'* ASP FormMail *
'* *
'* Do not remove this notice. *
'* *
'* Copyright 1999-2002 by Mike Hall. *
'* Please see http://www.brainjar.com for documentation and terms of use. *
'***************************************************************************
'- Customization of these values is required, see documentation. -----------

referers = Array("www.imagineadv.com , "imagineadv.com")
mailComp = "ASPMail, CDONTS, CDOSYS"
smtpServer = "mail.atl.cbeyond.com"
fromAddr = "gregg@imagineadv.com"

'- End required customization section. -------------------------------------

Response.Buffer = true
errorMsgs = Array()

'Check for form data.

if Request.ServerVariables("Content_Length") = 0 then
call AddErrorMsg("No form data submitted.")
end if

'Check if referer is allowed.

if UBound(referers) >= 0 then
validReferer = false
referer = GetHost(Request.ServerVariables("HTTP_REFERER"))
for each host in referers
if host = referer then
validReferer = true
end if
next
if not validReferer then
if referer = "" then
call AddErrorMsg("No referer.")
else
call AddErrorMsg("Invalid referer: '" & referer & "'.")
end if
end if
end if

'Check for the recipients field.

if Request.Form("_recipients") = "" then
call AddErrorMsg("Missing email recipient.")
end if

'Check all recipient email addresses.

recipients = Split(Request.Form("_recipients"), ",")
for each name in recipients
name = Trim(name)
if not IsValidEmailAddress(name) then
call AddErrorMsg("Invalid email address in recipient list: " & name &
".")
end if
next
recipients = Join(recipients, ",")

'Get replyTo email address from specified field, if given, and check it.

name = Trim(Request.Form("_replyToField"))
if name <> "" then
replyTo = Request.Form(name)
else
replyTo = Request.Form("_replyTo")
end if
if replyTo <> "" then
if not IsValidEmailAddress(replyTo) then
call AddErrorMsg("Invalid email address in reply-to field: " & replyTo
& ".")
end if
end if

'Get subject text.

subject = Request.Form("_subject")

'If required fields are specified, check for them.

if Request.Form("_requiredFields") <> "" then
required = Split(Request.Form("_requiredFields"), ",")
for each name in required
name = Trim(name)
if Left(name, 1) <> "_" and Request.Form(name) = "" then
call AddErrorMsg("Missing value for " & name)
end if
next
end if

'If a field order was given, use it. Otherwise use the order the fields were
'received in.

str = ""
if Request.Form("_fieldOrder") <> "" then
fieldOrder = Split(Request.Form("_fieldOrder"), ",")
for each name in fieldOrder
if str <> "" then
str = str & ","
end if
str = str & Trim(name)
next
fieldOrder = Split(str, ",")
else
fieldOrder = FormFieldList()
end if

'If there were no errors, build the email note and send it.

if UBound(errorMsgs) < 0 then

'Build table of form fields and values.

body = "<table border=""0"" cellpadding=""2"" cellspacing=""0"">" & vbCrLf
for each name in fieldOrder
body = body _
& "<tr valign=""top"">" _
& "<td><b>" & name & ":</b></td>" _
& "<td>" & Request.Form(name) & "</td>" _
& "</tr>" & vbCrLf
next
body = body & "</table>" & vbCrLf

'Add a table for any requested environmental variables.

if Request.Form("_envars") <> "" then
body = body _
& "<p> </p>" & vbCrLf _
& "<table border=""0"" cellpadding=""2"" cellspacing=""0"">" &
vbCrLf
envars = Split(Request.Form("_envars"), ",")
for each name in envars
name = Trim(name)
body = body _
& "<tr valign=""top"">" _
& "<td><b>" & name & ":</b></td>" _
& "<td>" & Request.ServerVariables(name) & "</td>" _
& "</tr>" & vbCrLf
next
body = body & "</table>" & vbCrLf
end if

'Send it.

str = SendMail()
if str <> "" then
AddErrorMsg(str)
end if

'Redirect if a URL was given.

if Request.Form("_redirect") <> "" then
Response.Redirect(Request.Form("_redirect"))
end if

end if %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>Form Mail</title>
<style type="text/css">

body {
background-color: #ffffff;
color: #000000;
font-family: Arial, Helvetica, sans-serif;
font-size: 10pt;
}
table {
border: solid 1px #000000;
border-collapse: collapse;
}
td, th {
border: solid 1px #000000;
border-collapse: collapse;
font-family: Arial, Helvetica, sans-serif;
font-size: 10pt;
padding: 2px;
padding-left: 8px;
padding-right: 8px;
}
th {
background-color: #c0c0c0;
}
.error {
color: #c00000;
}
</style>
</head>
<body>

<% if UBound(errorMsgs) >= 0 then %>
<p class="error">Form could not be processed due to the following errors:</p>
<ul>
<% for each msg in errorMsgs %>
<li class="error"><% = msg %></li>
<% next %>
</ul>
<% else %>
<table cellpadding="0" cellspacing="0">
<tr>
<th colspan="2" valign="bottom">
Thank you, the following information has been sent. Someone from our office
will confirm your order by email if it has been received. Please print this
page for your records:
</th>
</tr>
<% for each name in fieldOrder %>
<tr valign="top">
<td><b><% = name %></b></td>
<td><% = Request.Form(name) %></td>
</tr>
<% next %>
</table>
<% end if %>

</body>
</html>

<% '---------------------------------------------------------------------------
' Subroutines and functions.
'---------------------------------------------------------------------------
sub AddErrorMsg(msg)

dim n

'Add an error message to the list.

n = UBound(errorMsgs)
Redim Preserve errorMsgs(n + 1)
errorMsgs(n + 1) = msg

end sub

function GetHost(url)

dim i, s

GetHost = ""

'Strip down to host or IP address and port number, if any.

if Left(url, 7) = "http://" then
s = Mid(url, 8)
elseif Left(url, 8) = "https://" then
s = Mid(url, 9)
end if
i = InStr(s, "/")
if i > 1 then
s = Mid(s, 1, i - 1)
end if

getHost = s

end function

'Define the global list of valid TLDs.

dim validTlds

function IsValidEmailAddress(emailAddr)

dim i, localPart, domain, charCode, subdomain, subdomains, tld

'Check for valid syntax in an email address.

IsValidEmailAddress = true

'Parse out the local part and the domain.

i = InStrRev(emailAddr, "@")
if i <= 1 then
IsValidEmailAddress = false
exit function
end if
localPart = Left(emailAddr, i - 1)
domain = Mid(emailAddr, i + 1)
if Len(localPart) < 1 or Len(domain) < 3 then
IsValidEmailAddress = false
exit function
end if

'Check for invalid characters in the local part.

for i = 1 to Len(localPart)
charCode = Asc(Mid(localPart, i, 1))
if charCode < 32 or charCode >= 127 then
IsValidEmailAddress = false
exit function
end if
next

'Check for invalid characters in the domain.

domain = LCase(domain)
for i = 1 to Len(domain)
charCode = Asc(Mid(domain, i, 1))
if not ((charCode >= 97 and charCode <= 122) or (charCode >= 48 and
charCode <= 57) or charCode = 45 or charCode = 46) then
IsValidEmailAddress = false
exit function
end if
next

'Check each subdomain.

subdomains = Split(domain, ".")
for each subdomain in subdomains
if Len(subdomain) < 1 then
IsValidEmailAddress = false
exit function
end if
next

'Last subdomain should be a TDL.

tld = subdomains(UBound(subdomains))
if not IsArray(validTlds) then
call SetValidTlds()
end if
for i = LBound(validTlds) to UBound(validTlds)
if tld = validTlds(i) then
exit function
end if
next
IsValidEmailAddress = false

end function

sub setValidTlds()

'Load the global list of valid TLDs.

validTlds = Array("aero", "biz", "com", "coop", "edu", "gov", "info",
"int", "mil", "museum", "name", "net", "org", "pro", _
"ac", "ad", "ae", "af", "ag", "ai", "al", "am", "an", "ao", "aq", "ar",
"as", "at", "au", "aw", "az", _
"ba", "bb", "bd", "be", "bf", "bg", "bh", "bi", "bj", "bm", "bn", "bo",
"br", "bs", "bt", "bv", "bw", "by", "bz", _
"ca", "cc", "cd", "cf", "cg", "ch", "ci", "ck", "cl", "cm", "cn", "co",
"cr", "cu", "cv", "cx", "cy", "cz", _
"de", "dj", "dk", "dm", "do", "dz", "ec", "ee", "eg", "eh", "er", "es",
"et", _
"fi", "fj", "fk", "fm", "fo", "fr", _
"ga", "gd", "ge", "gf", "gg", "gh", "gi", "gl", "gm", "gn", "gp", "gq",
"gr", "gs", "gt", "gu",
 
Les Matthews replied to beckiehawk on 16 Jul 2004
Has the form page been setup (including using the required naming convention
for the form fields) are stipulated on this page -
http://www.brainjar.com/asp/formmail/?

The instructions on the brainjar site also state that the mailComp parameter
at the top of the script on the formmail page should be set to ONE of
"ASPMail", "CDONTS", "CDOSYS" or "JMail". You have THREE mail components
listed.

Are you sure that "mail.atl.cbeyond.com" is the smtp server for
imagineadv.com?
 
beckiehawk replied to Les Matthews on 16 Jul 2004
Yes I made sure all the variables in the form field were named as specified by
brainjar. I made sure the smtp server was what I have typed in there.

I tried to change the mail comp to just "CDO" which is what my host says they
have, but it still won't go to my email.

I get a very nice page with a table that has all my form information in it,
but it isn't being sent to me.
 
Les Matthews replied to beckiehawk on 16 Jul 2004
Try "CDOSYS"
CDO and CDOSYS are the same thing, but the example on brainjar was CDOSYS
 

Archived message: ASP form to email (Macromedia Dreamweaver)