5 replies [Last post]
GuyDavies
GuyDavies's picture
Offline
Enthusiast
Manchester, UK
Last seen: 13 years 31 weeks ago
Manchester, UK
Joined: 2004-09-11
Posts: 55
Points: 0

Hi, I am trying to create a form and an asp script to send the contents of said form to an email address of my choice but when I tried to test my form I got the following message:

Quote:

Server object error 'ASP 0177 : 800401f3'

Server.CreateObject Failed

/contact.asp, line 37

800401f3

The code for my form and my asp script are as follows, is there anyone out there who could take a quick look and suggest a solution / reason for this problem? Thanks in advance for anyone who takes a look it's much appreciated! (Oh by the way the email address in the asp script has been replaced for security reasons Laughing out loud)

<form id="contact_form" method="post" action="contact.asp">
	<table width="400" border="0" cellspacing="0" cellpadding="0">
  	<tr>
    <td colspan="2"><p>Fields marked (*) are required</p></td>
    </tr>
  	<tr>
    <td><p>FirstName:* </p></td>
    <td><input class="blue" name="FirstName" type="text" size="40" maxlength="25" /></td>
  	</tr>
  	<tr>
    <td><p>LastName:* </p></td>
    <td><input class="blue" name="LastName" type="text" size="40" maxlength="25" /></td>
  	</tr>
  	<tr>
    <td><p>Email:* </p></td>
    <td><input class="blue" name="Email" type="text" size="40" maxlength="50" /></td>
  	</tr>
  	<tr>
    <td><p>Message:* </p></td>
    <td><textarea class="blue" name="Message" cols="60" rows="8"></textarea></td>
  	</tr>
  	<tr>
    <td colspan="2"><input class="submit" type="submit" name="submit" value="Submit" /></td>
    </tr>
	</table>
	</form>

<%

' declare variables
Dim EmailTo
Dim Subject
Dim FirstName
Dim LastName
Dim Email
Dim Message

' get posted data into variables 
EmailTo = "[email protected]"
Subject = Trim(Request.Form("Subject")) 
FirstName = Trim(Request.Form("FirstName")) 
LastName = Trim(Request.Form("LastName")) 
Email = Trim(Request.Form("Email")) 
Message = Trim(Request.Form("Message")) 

' validation
Dim validationOK
validationOK=true
If (Trim(FirstName)="") Then validationOK=false
If (Trim(LastName)="") Then validationOK=false
If (Trim(Email)="") Then validationOK=false
If (Trim(Message)="") Then validationOK=false
If (validationOK=false) Then Response.Redirect("error.html?" & EmailFrom)

' prepare email body text
Dim Body
Body = Body & "FirstName: " & FirstName & VbCrLf
Body = Body & "LastName: " & LastName & VbCrLf
Body = Body & "Email: " & Email & VbCrLf
Body = Body & "Message: " & Message & VbCrLf

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

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

http//www.guydavies.eclipse.co.uk/

Tags:
Tyssen
Tyssen's picture
Offline
Moderator
Brisbane
Last seen: 8 years 15 weeks ago
Brisbane
Timezone: GMT+10
Joined: 2004-05-01
Posts: 8201
Points: 1386

ASP Email Form Problem

My first guess would be that CDONTS isn't installed on your server.

How to get help
Post a link. If you can't post a link, jsFiddle it.
My blog | My older articles | CSS Reference

GuyDavies
GuyDavies's picture
Offline
Enthusiast
Manchester, UK
Last seen: 13 years 31 weeks ago
Manchester, UK
Joined: 2004-09-11
Posts: 55
Points: 0

ASP Email Form Problem

Hi Tyssen thanks for the reply, I am new to ASP I normally use a PHP script for emailing forms but my clients hosting package only suports ASP!

I have done a bit of searching and found that his hosting company uses the mail component aspmail. As I mention I don't really know ASP at all can you suggest how my contact.asp script should look? Laughing out loud

http//www.guydavies.eclipse.co.uk/

Tyssen
Tyssen's picture
Offline
Moderator
Brisbane
Last seen: 8 years 15 weeks ago
Brisbane
Timezone: GMT+10
Joined: 2004-05-01
Posts: 8201
Points: 1386

ASP Email Form Problem

Change the lines that refer to CDONTS based on this: http://www.aspwebpro.com/aspscripts/email/aspmail.asp

How to get help
Post a link. If you can't post a link, jsFiddle it.
My blog | My older articles | CSS Reference

GuyDavies
GuyDavies's picture
Offline
Enthusiast
Manchester, UK
Last seen: 13 years 31 weeks ago
Manchester, UK
Joined: 2004-09-11
Posts: 55
Points: 0

ASP Email Form Problem

Hi again Tyssen, thanks for your help. i thought I would crack it with this code but I now get a new error, code and error follow:

<%
DIM strEmail, strFirstName, strLastName, strComments, Mailer
strEmail = request.form("Email")
strFirstName = request.form("FirstName")
strLastName = request.form("LastName")
strMessage = request.form("Message")

DIM Mailer, strMsgHeader, qryItem, strMsgInfo
Set Mailer = Server.CreateObject("SMTPsvg.Mailer")
Mailer.FromName = "Website"
Mailer.FromAddress= "[email protected]"
Mailer.ReplyTo = strEmail
Mailer.RemoteHost = "server.host.com"
Mailer.AddRecipient "Company", "[email protected]"
Mailer.Subject = "Company Website: Contact Form"
strMsgHeader = "This mail message was sent from the www.company.com Contact Form" & vbCrLf & vbCrLf
Mailer.ContentType = "text/html"
Mailer.BodyText = strMsgHeader & vbCrLf & "Email: " & Request.Form("Email") & _
vbCrLf & "First Name: " & Request.Form("FirstName") & _
vbCrLf & "Last Name: " & Request.Form("LastName") & _
vbCrLf & "Message: " & Request.Form("Message")

IF Mailer.SendMail THEN
Response.Write strFirstName & ",<br>"
Response.Write "Your message has been successfully sent."
ELSE
Response.Write "The following error occurred while sending your message: " & Mailer.Response
END IF
%>

Quote:

Microsoft VBScript compilation error '800a0411'

Name redefined

/contact.asp, line 8

DIM Mailer, strMsgHeader, qryItem, strMsgInfo
----^

Also Tyssen, if I wanted to open a html page rather than display the response message how would I do this?

Cheer Laughing out loud

http//www.guydavies.eclipse.co.uk/

Tyssen
Tyssen's picture
Offline
Moderator
Brisbane
Last seen: 8 years 15 weeks ago
Brisbane
Timezone: GMT+10
Joined: 2004-05-01
Posts: 8201
Points: 1386

ASP Email Form Problem

GuyDavies wrote:

<%
DIM strEmail, strFirstName, strLastName, strComments, Mailer
DIM Mailer, strMsgHeader, qryItem, strMsgInfo



As the error message suggests, you've defined Mailer twice.

If you want error messages to be displayed in a page of your choosing rather than the default page you're getting at the moment (if that's what you're asking), you'll need to Google ASP error trapping/reporting, although it's probably going to involve on error resume next.

How to get help
Post a link. If you can't post a link, jsFiddle it.
My blog | My older articles | CSS Reference