PDA

View Full Version : Sendmail and ezines


Moses
31-Aug-2004, 03:25 PM
I have a form which web designers set up on a previous site which I now want to use on my new Actinic site for collecting users' registrations. Basically, I will be producing an ezine promoting my goods and the form is to encourage people to sign up for it. I have two questions:

1. How do I get the form to submit the details to my email address? - currently it is set up with this coding:

<form method="POST" action="sendmail.asp" onsubmit="return FrontPage_Form1_Validator(this)" language="JavaScript" name="FrontPage_Form1">

<input type="hidden" name="_recipients" value="[My email address inserted here]">

I have included the sendmail.asp file within Site 1 and loaded up the form itself as an html page.

The form appears correctly but when you fill it out and click Submit it goes to a HTTP 404 - File not found error.

When I load up the site it comes up with an error in relation to the form which says "[name of form html page] FOOTER LOAD FUNCTION, ON LOAD."

2. Assuming the above can be fixed, is this the best way of going about the exercise of getting people to sign up to the ezine? Or is it better to use another kind of software?

Thanks in anticipation of your help.

crazylegsreilly
01-Sep-2004, 12:38 PM
Would you be able to add a copy of the form code file and the ASP code file?

Moses
01-Sep-2004, 03:06 PM
Thanks here is the code for the form:



<html>

<head>
<meta http-equiv="Content-Language" content="en-gb">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
</head>

<body>

<p><b><font size="4" color="#6666FF" face="Verdana">Sign up to receive ArtHorse
Preview, our quarterly e-zine</font></b></p>
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="450">
<!--webbot BOT="GeneratedScript" PREVIEW=" " startspan --><script Language="JavaScript" Type="text/javascript"><!--
function FrontPage_Form1_Validator(theForm)
{

if (theForm.FirstName.value == "")
{
alert("Please enter a value for the \"FirstName\" field.");
theForm.FirstName.focus();
return (false);
}

if (theForm.FirstName.value.length < 3)
{
alert("Please enter at least 3 characters in the \"FirstName\" field.");
theForm.FirstName.focus();
return (false);
}

if (theForm.Surname.value == "")
{
alert("Please enter a value for the \"Surname\" field.");
theForm.Surname.focus();
return (false);
}

if (theForm.Surname.value.length < 3)
{
alert("Please enter at least 3 characters in the \"Surname\" field.");
theForm.Surname.focus();
return (false);
}

if (theForm.email.value == "")
{
alert("Please enter a value for the \"email\" field.");
theForm.email.focus();
return (false);
}

if (theForm.email.value.length < 3)
{
alert("Please enter at least 3 characters in the \"email\" field.");
theForm.email.focus();
return (false);
}
return (true);
}
//--></script><!--webbot BOT="GeneratedScript" endspan --><form method="POST" action="sendmail.asp" onsubmit="return FrontPage_Form1_Validator(this)" language="JavaScript" name="FrontPage_Form1"><tr>
<td width="50%" height="19"><b>
<font face="Verdana" size="2" color="#6666FF">What is your name?</font></b></td>
<td width="50%" height="19">&nbsp;</td>
</tr>
<tr>
<td width="50%" height="22"><font face="Verdana" size="2" color="#6666FF">
Title:</font></td>
<td width="50%" height="22"><select size="1" name="Title">
<option>Ms</option>
<option>Mrs</option>
<option>Miss</option>
<option>Mr</option>
</select></td>
</tr>
<tr>
<td width="50%" height="22"><font face="Verdana" size="2" color="#6666FF">
First name:</font></td>
<td width="50%" height="22">
<!--webbot bot="Validation" b-value-required="TRUE" i-minimum-length="3" --><input type="text" name="FirstName" size="20"></td>
</tr>
<tr>
<td width="50%" height="22"><font face="Verdana" size="2" color="#6666FF">
Surname:</font></td>
<td width="50%" height="22">
<!--webbot bot="Validation" b-value-required="TRUE" i-minimum-length="3" --><input type="text" name="Surname" size="20"></td>
</tr>
<tr>
<td width="50%" height="19">&nbsp;</td>
<td width="50%" height="19">&nbsp;</td>
</tr>
<tr>
<td width="50%" height="22"><b>
<font face="Verdana" size="2" color="#6666FF">What is your e-mail address?</font></b></td>
<td width="50%" height="22">
<!--webbot bot="Validation" b-value-required="TRUE" i-minimum-length="3" --><input type="text" name="email" size="20"></td>
</tr>
<tr>
<td width="50%" height="19">&nbsp;</td>
<td width="50%" height="19">&nbsp;</td>
</tr>
<tr>
<td width="50%" height="22"><b>
<font face="Verdana" size="2" color="#6666FF">Where did you hear about us?</font></b></td>
<td width="50%" height="22"><select size="1" name="Where_From">
<option>Web search</option>
<option>Word of mouth</option>
<option>Link from other site</option>
<option>Press article</option>
<option>Advert</option>
</select></td>
</tr>
<tr>
<td width="50%" height="19">&nbsp;</td>
<td width="50%" height="19">&nbsp;</td>
</tr>
<tr>
<td width="50%" height="32"><b>
<font face="Verdana" size="2" color="#6666FF">Do you have any particular
areas of interest?</font></b></td>
<td width="50%" height="32">&nbsp;</td>
</tr>
<tr>
<td width="50%" height="20"><font face="Verdana" size="2" color="#6666FF">
Print:</font></td>
<td width="50%" height="20">
<input type="checkbox" name="Print" value="Yes"></td>
</tr>
<tr>
<td width="50%" height="20"><font face="Verdana" size="2" color="#6666FF">
Original:</font></td>
<td width="50%" height="20">
<input type="checkbox" name="Original" value="Yes"></td>
</tr>
<tr>
<td width="50%" height="20"><font face="Verdana" size="2" color="#6666FF">
Watercolour:</font></td>
<td width="50%" height="20">
<input type="checkbox" name="Watercolour" value="Yes"></td>
</tr>
<tr>
<td width="50%" height="20"><font face="Verdana" size="2" color="#6666FF">
Oils:</font></td>
<td width="50%" height="20">
<input type="checkbox" name="Oils" value="Yes"></td>
</tr>
<tr>
<td width="50%" height="20"><font face="Verdana" size="2" color="#6666FF">
Sculpture:</font></td>
<td width="50%" height="20">
<input type="checkbox" name="Sculpture" value="Yes"></td>
</tr>
<tr>
<td width="50%" height="20"><font face="Verdana" size="2" color="#6666FF">
Photography:</font></td>
<td width="50%" height="20">
<input type="checkbox" name="Photography" value="Yes"></td>
</tr>
<tr>
<td width="50%" height="22"><font face="Verdana" size="2" color="#6666FF">
Other:</font></td>
<td width="50%" height="22"><input type="text" name="Other" size="20"></td>
</tr>
<tr>
<td width="100%" colspan="2" height="48">


<input type="hidden" name="_recipients" value="sales@[ ].co.uk">
<input type="hidden" name="_replyToField" value="">
<input type="hidden" name="_replyTo" value="">
<input type="hidden" name="_requiredFields" value="">
<input type="hidden" name="_fieldOrder" value="">
<input type="hidden" name="_subject" value="Art Horse: Preview Subscription">

<!-- End of hidden fields //-->

</td>
</tr>
<tr>
<td width="100%" colspan="2" align="center" height="27"><input type="submit" value="Submit" name="Submit-Form">&nbsp; <input type="reset" value="Reset" name="B2"></td>
</tr>
<tr>
<td width="100%" colspan="2" height="48">
<font face="Verdana" size="1" color="#6666FF">&nbsp; <br>
We will only use the details
you give us to keep you updated about the [ ] Gallery.&nbsp; If at any time
you no longer wish to receive the updates let us know. <p> <font color="#800000" size="2" face="Verdana">If you have any problems in using this
form please tell us and supply the above details by e-mail at </font>
<font color="#666666" size="2" face="Verdana">
<a href="[mailto:[ ]"><font color="#800000">[site url]</font></a></font><font color="#800000" size="2" face="Verdana"> or post
(address available on request).</font><br>
&nbsp; </font></td>
</tr>
</form>
</table>

</body>

</html>

Moses
01-Sep-2004, 03:09 PM
Here is the asp code: remainder to follow in next posting


<%@ LANGUAGE="VBScript" %>
<%


'- Customization of these values is required. -----------

referers = Array("www.[ ]", "[ ]","www.[ ]") ' this script is only valid if fired from these domains
mailComp = "JMail" ' use jmail for sending
smtpServer = "mail.hostedbyhumans.net" ' the smtp server address please notet this will change to nemesis when i move the server
fromAddr = "sales@[]" ' the email to be used in th efrom address.

'- 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>&nbsp;</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>

Moses
01-Sep-2004, 03:10 PM
Part II of the asp code:

<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:
</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", "gw", "gy", _
"hk", "hm", "hn", "hr", "ht", "hu", _
"id", "ie", "il", "im", "in", "io", "iq", "ir", "is", "it", _
"je", "jm", "jo", "jp", _
"ke", "kg", "kh", "ki", "km", "kn", "kp", "kr", "kw", "ky", "kz", _
"la", "lb", "lc", "li", "lk", "lr", "ls", "lt", "lu", "lv", "ly", _
"ma", "mc", "md", "mg", "mh", "mk", "ml", "mm", "mn", "mo", "mp", "mq", "mr", "ms", "mt", "mu", "mv", "mw ", "mx", "my", "mz", _
"na", "nc", "ne", "nf", "ng", "ni", "nl", "no", "np", "nr", "nu", "nz", _
"om", _
"pa", "pe", "pf", "pg", "ph", "pk", "pl", "pm", "pn", "pr", "ps", "pt", "pw", "py", _
"qa", _
"re", "ro", "ru", "rw", _
"sa", "sb", "sc", "sd", "se", "sg", "", "si", "sj", "sk", "sl", "sm", "sn", "so", "sr", "st", "sv", "sy", "sz", _
"tc", "td", "tf", "tg", "th", "tj", "tk", "tm", "tn", "to", "tp", "tr", "tt", "tv", "tw", "tz", _
"ua", "ug", "uk", "um", "us", "uy", "uz", _
"va", "vc", "ve", "vg", "vi", "vn", "vu", _
"wf", "ws", _
"ye", "yt", "yu", _
"za", "zm", "zw")

end sub

function FormFieldList()

dim str, i, name

'Build an array of form field names ordered as they were received.

str = ""
for i = 1 to Request.Form.Count
for each name in Request.Form
if Left(name, 1) <> "_" and Request.Form(name) is Request.Form(i) then
if str <> "" then
str = str & ","
end if
str = str & name
exit for
end if
next
next
FormFieldList = Split(str, ",")

end function

function SendMail()

dim mailObj, cdoMessage, cdoConfig
dim addrList

'Send email based on mail component. Uses global variables for parameters
'because there are so many.

SendMail = ""

'Send email (CDONTS version). Note: CDONTS doesn't support a reply-to
'address and has no error checking.

if mailComp = "CDONTS" then
set mailObj = Server.CreateObject("CDONTS.NewMail")
mailObj.BodyFormat = 0
mailObj.MailFormat = 0
mailObj.From = fromAddr
mailObj.To = recipients
mailObj.Subject = subject
mailObj.Body = body
mailObj.Send
set mailObj = Nothing
exit function
end if

'Send email (CDOSYS version).

if mailComp = "CDOSYS" then
set cdoMessage = Server.CreateObject("CDO.Message")
set cdoConfig = Server.CreateObject("CDO.Configuration")
cdoConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
cdoConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mail"
cdoConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = smtpServer
cdoConfig.Fields.Update
set cdoMessage.Configuration = cdoConfig
cdoMessage.From = fromAddr
cdoMessage.To = recipients
cdoMessage.Subject = subject
cdoMessage.HtmlBody = body
on error resume next
cdoMessage.Send
if Err.Number <> 0 then
SendMail = "Email send failed: " & Err.Description & "."
end if
set cdoMessage = Nothing
set cdoConfig = Nothing
exit function
end if

'Send email (JMail version).

if mailComp = "JMail" then
set mailObj = Server.CreateObject("JMail.SMTPMail")
mailObj.Silent = true
mailObj.ServerAddress = smtpServer
mailObj.Sender = fromAddr
mailObj.ReplyTo = replyTo
mailObj.Subject = subject
addrList = Split(recipients, ",")
for each addr in addrList
mailObj.AddRecipient Trim(addr)
next
mailObj.ContentType = "text/html"
mailObj.Body = body
if not mailObj.Execute then
SendMail = "Email send failed: " & mailObj.ErrorMessage & "."
end if
exit function
end if

'Send email (ASPMail version).

if mailComp = "ASPMail" then
set mailObj = Server.CreateObject("SMTPsvg.Mailer")
mailObj.FromAddress = fromAddr
mailObj.RemoteHost = smtpServer
mailObj.ReplyTo = replyTo
for each addr in Split(recipients, ",")
mailObj.AddRecipient "", Trim(addr)
next
mailObj.Subject = subject
mailObj.ContentType = "text/html"
mailObj.BodyText = body
if not mailObj.SendMail then
SendMail = "Email send failed: " & mailObj.Response & "."
end if
exit function
end if

end function %>

Jan
02-Sep-2004, 06:09 AM
You can add HTML code to an Actinic brochure page or product by putting
!!< at the beginning of the code segment and >!! at the end, so you can add your form to a page that way, another way to do this would be to edit an Actinic template and add the HTML into that in the appropriate place (no markers required then). Then you just put your asp modules onto your website in the acatalog directory and all should work, we have done this on www.mole-end.biz, and look at the source for our email form at the bottom of the page, our free review page also uses a form like this.

Regards

Moses
02-Sep-2004, 07:13 PM
Thanks but I'm afraid I am still lost with this! I have no problem putting the form onto the site, either within the place holders or as a section in its own right as I have done. What I am not sure about is the asp code. This does not seem to work.

I have just tried to amend a copy of the standard Contact Us html in Actinic to include the operative parts of my registration form but this does not seem to work.

Is this because the form has been created in FrontPage?

All very frustrating as this is now the only thing standing in the way of taking the site live.

I am not a programmer so this is all a bit alient to me :confused: