Forum Moderators: open

Message Too Old, No Replies

Error on line 36 - Contact Form

Works up to the error at least...

         

JAB Creations

1:47 am on Feb 24, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Do a search for "form generator" on google and this is where the code originates from. It will send you to the error page if you don't fill all the fields in however it will not actually send the email.

I'm guessing the form generator is a little old and does not run on newer versions of IIS? I really don't know squat about ASP/VB but maybe someone will be able to spot the error on line 36...

Set mail = Server.CreateObject("CDONTS.NewMail")

Here are the ASP script and form pages...

contact.asp

<%
' declare variables
Dim EmailFrom
Dim EmailTo
Dim Subject
Dim name
Dim comments

' get posted data into variables
EmailFrom = Trim(Request.Form("EmailFrom"))
EmailTo = "test@yahoo.com"
Subject = Trim(Request.Form("Subject"))
name = Trim(Request.Form("name"))
comments = Trim(Request.Form("comments"))

' validation
Dim validationOK
validationOK=true
If (Trim(EmailFrom)="") Then validationOK=false
If (Trim(name)="") Then validationOK=false
If (Trim(comments)="") Then validationOK=false
If (validationOK=false) Then Response.Redirect("error.htm?" & EmailFrom)

' prepare email body text
Dim Body
Body = Body & "name: " & name & VbCrLf
Body = Body & "comments: " & comments & VbCrLf

' send email
Dim mail
Set mail = Server.CreateObject("CDONTS.NewMail")
mail.To = EmailTo
mail.From = EmailFrom
mail.Subject = Subject
mail.Body = Body
mail.Send

' redirect to success page
Response.Redirect("ok.htm?" & EmailFrom)
%>

For test purposes here is the clientside form...

form.html

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Contact Form</title>
<style type="text/css">
label {
border: #000 dotted 1px;
float: left;
width: 100px;
}
</style>
</head>

<body>

<form method="POST" action="contact.asp">
<fieldset>
<label for="name">Name:</label><input id="name" name="name" type="text" />
<br />
<label for="emailfrom">Email:</label><input id="emailfrom" name="emailfrom" type="text" />
<br />
<label for="subject">Subject:</label><input id="subject" name="subject" type="text" />
<br />
<label for="comments">Comments:</label><textarea id="comments" name="comments"></textarea>
<br />
<input name="submit" type="submit" value="Send" />
</fieldset>
</form>

</body>
</html>

carguy84

3:05 pm on Mar 1, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



you most likely want to use:
set mail = Server.CreateObject("CDO.Message")

This is what IIS 2k3 uses by default now. It no longer comes installed with CDONTS.

Then, change this line:
mail.Body = Body

to:

mail.TextBody = Body
if you are submitting just regular text

or

mail.HTMLBody = Body
if you are submitting HTML in your email

Chip-

Iguana

3:07 pm on Mar 1, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Check that you have the IIS SMTP server running - and that the CDONTS.dll is present and registered

The code looks fine