Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form to text file to Email with CDONTS?????

Status
Not open for further replies.

JWTaylor

Technical User
Jan 19, 2003
4
GB
Hello All,

I am new to asp and having a little trouble accomplishing what seems
to be a relatively simple task. I want take input from a html form and
save it to a text file, then I would like to email this information to
myself, then redirect the visitor to a thank you page. I have CDONTS
installed on the server and have the email form with validation
working fine.. I am having trouble with writing to the text file and I
haven't been able to find much info on accomplishing both these tasks
from the same source. I have posted the error I am receiving along
with my butchered code..I commented at line 132 where I am getting the error Any help , advice, links to samples would be
greatly appreciated..

Thanks and good day.

JW Taylor
please email me at josh.taylor@MethodSmart.com


My error:
Server object error 'ASP 0177 : 800a0046'

Server.CreateObject Failed

/mailcontact.asp, line 132

The operation completed successfully.


My Code:
<%

'Broken Script by Josh Taylor
Dim oEmail
Set oEmail = Server.CreateObject(&quot;CDONTS.NewMail&quot;)

'Defining all of the variables required for the form fields.
Requesting the form fields and setting them as variables.

Dim
eFrom,eEmail,eSubject,eComments,eCompany,eTitle,eAddress,eCi
ty,eState,eZipcode,eCountry,ePhone,eExperience,eReferrals,eP
rospective,eSponsor

eFrom = Request.Form(&quot;name&quot;)
eEmail = Request.Form(&quot;email&quot;)
eSubject = &quot;Contact us Form&quot;
eComments = Request.Form(&quot;comments&quot;)
eCompany = Request.Form(&quot;Company&quot;)
eTitle = Request.Form(&quot;title&quot;)
eAddress = Request.Form(&quot;Address&quot;)
eCity = Request.Form(&quot;city&quot;)
eState = Request.Form(&quot;state&quot;)
eZipcode = Request.Form(&quot;zipcode&quot;)
eCountry = Request.Form(&quot;country&quot;)
ePhone = Request.Form(&quot;phone&quot;)
eExperience = Request.Form(&quot;experience&quot;)
eReferrals = Request.Form(&quot;InternetSearch&quot;) &
Request.Form(&quot;skymagazine&quot;) & Request.Form(&quot;NPR_Radio&quot;) &
Request.Form(&quot;Newspaper&quot;) & Request.Form(&quot;whichnewspaper&quot;) &
Request.Form(&quot;employerreferral&quot;) &
Request.Form(&quot;employerreferraltext&quot;) &
Request.Form(&quot;personalalumnireferral&quot;) &
Request.Form(&quot;personalalumniname&quot;) & Request.Form
(&quot;openhouse&quot;) &
Request.Form(&quot;other&quot;) & Request.Form(&quot;otherreferral&quot;)
eProspective = Request.Form(&quot;prospectivestudent&quot;)
eSponsor = Request.Form(&quot;employeesponsor&quot;)

'Checking that there is some data in the input fields. If
there is no
data then an error is produced, which can be found near the
bottom of
this script.

If Request.Form(&quot;email&quot;) <> &quot;&quot; Then
If Request.Form(&quot;comments&quot;) <> &quot;&quot; Then
If Request.Form(&quot;name&quot;) <> &quot;&quot; Then
If Request.Form(&quot;experience&quot;) <> &quot;&quot; Then
If eReferrals <> &quot;&quot; Then



'Getting some information from the user, such as their
platform,
referer, time, date, and host.

Dim sPlatform,sReferer,sTime,sDate,sHost
sPlatform = request.servervariables(&quot;HTTP_USER_AGENT&quot;)
sReferer = request.servervariables(&quot;HTTP_Referer&quot;)
sTime = Time
sDate = Date
sHost = request.servervariables(&quot;REMOTE_HOST&quot;)

'The email address it is being sent to.


oEmail.To = &quot;josh.taylor@temp.com&quot;

'Who the email is from, using the variable we defined above.


oEmail.From = eFrom

'The subject of the message again using the variable we
defined above.

oEmail.Subject = eSubject

'Inserting the body content, using the variable, and all
that user
information we found out. VBCRLF is VBScript formatting to
insert a
line break.


oEmail.Body = &quot;Name: &quot; & eName & vbcrlf&_
&quot;Email: &quot; & eEmail & vbcrlf&_
&quot;Street Address: &quot; & eAddress & vbcrlf&_
&quot;City: &quot; & eCity & vbcrlf&_
&quot;State: &quot; & eState & vbcrlf&_
&quot;Zipcode: &quot; & eZipcode & vbcrlf&_
&quot;Country: &quot; & eCountry & vbcrlf&_
&quot;Telephone: &quot; & ePhone & vbcrlf&_
&quot;Company: &quot; & eCompany & vbcrlf&_
&quot;Title: &quot; & eTitle & vbcrlf&_
&quot;Years of Managerial Experience: &quot; & eExperience & vbcrlf&_
&quot; &quot; & vbcrlf&_
&quot;How did you hear about ? &quot; & vbcrlf&_
&quot;Referrals: &quot; & eReferrals & vbcrlf&_
&quot; &quot; & vbcrlf&_
&quot;Are you a prospective student: &quot; & eProspective & vbcrlf&_
&quot;Are you a prospective employer sponsor: &quot; & eSponsor &
vbcrlf&_
&quot;Comments or Question: &quot; & eComments & vbcrlf&_
&quot; &quot; & vbcrlf&_


&quot;Additional Information------------&quot; & vbcrlf&_
&quot;User Platform: &quot; & sPlatform & vbcrlf&_
&quot;User URL: &quot; & sReferer & vbcrlf&_
&quot;Time Sent: &quot; & sTime & vbcrlf&_
&quot;Date Sent: &quot; & sDate & vbcrlf&_
&quot;User Host: &quot; & sHost & vbcrlf&_
&quot;User Name: &quot; & tUserName

'Send the email.

oEmail.Send

'This is the validation text

Else
response.write(&quot;Please tell us how you heard about the
program.<br><br><a href='javascript:history.back()'>:: GO
BACK
::</a>&quot;)
End If
Else
response.write(&quot;Please enter a your years of managerial
experience<br><br><a href='javascript:history.back()'>:: GO
BACK
::</a>&quot;)
End If
Else
response.write(&quot;Please enter your name. <br><br><a
href='javascript:history.back()'>:: GO BACK ::</a>&quot;)
End If
Else
response.write(&quot;Please enter a question or comment. <br><br><a
href='javascript:history.back()'>:: GO BACK ::</a>&quot;)
End If
Else
response.write(&quot;Please enter your email address.<br><br><a
href='javascript:history.back()'>:: GO BACK ::</a>&quot;)
End If

%>
<%

Dim MyWord 'What we will put into the text file.
Dim objFSO 'FileSystemObject Variable
Dim objFile 'File Object Variable

MyWord = Request.Form(&quot;name&quot;) 'Put in the string into
the text
file.

'This locates our text file that will be written to.
strFile = Server.MapPath(&quot;contactus.txt&quot;)

' Create an instance of the FileSystemObject
Set objFSO = Server.CreateObject
(&quot;Scripting.FileSystemObject&quot;)

'LINE 132 below causing the error
Set objFile = objFSO.OpenTextFile(strFile, 8, True)

'Here we actually append new information to
the text
file.
objFile.Write Server.HTMLEncode(MyWord)

'This gives us a new line for the next
piece of
information.
objFile.WriteLine &quot;&quot;

' Close the file and dispose of our objects
objFile.Close
Set objFile = Nothing
Set objFSO = Nothing

'Give the user a thank you message for sending the email.

response.redirect &quot;/thanks.htm&quot;
%>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top