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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

email contact form with CDO using asp page

Status
Not open for further replies.

woodje

Technical User
May 24, 2004
16
US
Hello,

I have a form in html that I am trying to email the contents to a location using an asp page. I have included the code for the form and the asp page below. When I exectue this I am getting an http 500 internal error. Page can't be displayed. When you use the submit button or try to access the page directly. Please take a look and let me know your thoughts.

Jeff

Form ***
<form id="client_email" action="contact.asp" method="GET">

<tr>
<td class="user main" bgcolor="#eeeeee" background="img/spacer.gif">
<div><div align="right"><font size="2">Full name:</font><!--"''"--></div></div>
</td>
<td class="user main" bgcolor="#FFFFFF" background="img/spacer.gif" TlxField="area1" align="left" valign="middle">
<div>
<!--fe --><input type="text" name="client_name" value="" maxlength="200" size="30">
<!--/fe --></div>
</td>
</tr>
<tr>
<td class="user main" bgcolor="#eeeeee" background="img/spacer.gif">
<div><DIV align=right><FONT size=2>Email address:</FONT><!--"''"--></DIV></div>
</td>
<td class="user main" bgcolor="#FFFFFF" background="img/spacer.gif">
<div>
<!--fe --><input type="text" name="client_senderemail" value="" maxlength="200" size="30">
<!--/fe --></div>
</td>
</tr>
<tr>
<td class="user main" bgcolor="#eeeeee" background="img/spacer.gif">
<div><DIV align=right><FONT size=2>Comment or question:</FONT><!--"''"--></DIV></div>
</td>
<td class="user main" bgcolor="#FFFFFF" background="img/spacer.gif">
<div>
<!--fe --><textarea name="client_message" cols="30" rows="5"></textarea>
<!--/fe --></div>
</td>
</tr>
<tr>
<td class="user main" bgcolor="#eeeeee" background="img/spacer.gif">
<div><DIV align=right><FONT size=2>What is the best way to contact you?</FONT><!--"''"--></DIV></div>
</td>
<td class="user main" bgcolor="#FFFFFF" background="img/spacer.gif">
<div>
<!--fe --><input type="radio" name="client_contactway" value="email"><font size="2">By email</font>
<!--/fe --></div>
<div>
<!--fe --><input type="radio" name="client_contactway" value="phone"><font size="2">By phone</font>
<!--/fe --></div>
</td>
</tr>
<tr>
<td class="user main" bgcolor="#eeeeee" background="img/spacer.gif">
<div><DIV align=right><FONT size=2>If by phone, what is the best time of day to get in touch with you?</FONT><!--"''"--></DIV></div>
</td>
<td class="user main" bgcolor="#FFFFFF" background="img/spacer.gif">
<div>
<!--fe --><textarea name="client_contacttime" cols="30" rows="5"></textarea>
<!--/fe --></div>
</td>
</tr>
<tr>
<td class="user main" bgcolor="#eeeeee" background="img/spacer.gif" align="center" valign="middle">&nbsp;</td>
<td class="user main" bgcolor="#FFFFFF" background="img/spacer.gif" align="center" valign="middle">
<div>
<!--fe --><input type="image" src="img/submit_white.gif" name="submit" value="Submit">
<!--/fe --></div>
</td>
</tr>
</form>

Asp contact code
<%
Dim ObjSendMail
Dim iConf
Dim Flds

set reg = New RegExp
reg.Pattern = "^[A-Za-z0-9\._\-]+@([A-Za-z0-9\._\-]+\.)+[A-Za-z0-9\._\-]+$"
set m = reg.Execute(Request.QueryString("client_email"))

name = Request.QueryString("client_name")
senderemail = Request.QueryString("client_senderemail")
message = Request.QueryString("client_message")
contactway = Request.QueryString("client_contactway")
contacttime = Request.QueryString("client_contacttime")

Set ObjSendMail = Server.CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")
Set Flds = iConf.Fields

Flds(" = 1

'**** Path below may need to be changed if it is not correct
Flds(" = "c:\inetpub\mailroot\pickup"
Flds.Update

Set ObjSendMail.Configuration = iConf
ObjSendMail.To = "webmaster@jwcsconsultingservice.com"
ObjSendMail.Subject = "A message from your Contacts Page from " & name &
ObjSendMail.From = "contactform@junkcarsfl.com"

' we are sending a text email.. simply switch the comments around to send an html email instead
'ObjSendMail.HTMLBody = "<html><head><title>Contact Letter</title></head><body><br>" & street & & city & & state & & zip & & name & & senderemail & & message & & contactway & & contacttime & "</body></html>"
ObjSendMail.TextBody = "this is the body"

ObjSendMail.Send
Response.Write("Your email was sent")

Set ObjSendMail = Nothing
%>
 
sorry - didn't realize you had already posted it here...I posted this mesage in the other thread in the HTML forum...


A "page cannot be displayed" error usually is caused by the page not existing where you are trying to access it.

If the page did exist and you have the "show friendly http error messages" box unchecked, you should get a detailed description of the error including the line number that is causing the page to break.

Try this:

at the very top of the "contact.asp" (first two lines) write:


CODE
<% response.write "Hello World" %>
<% response.end %>

then go directly to the page - what do you see?

TIP: trying googling the answer before posting, you'll find that more times than not someone else somewhere has had the same request and posted an answer online.
----
I have recently been semi-converted to ensuring all my code (well most of it) works in both javascript and non-javascript enabled browsers
 
Here is the full error message.

Microsoft VBScript compilation error '800a0401'

Expected end of statement

/contact.asp, line 31

ObjSendMail.Subject = ""A message from your Contacts Page from " & name &"

 
The problem seems to be in the wording to try and put the contact name from the form and append it to the text in the subject field. If I rewrite the code to read

ObjSendMail.Subject = "A message from your Contacts Page from "

Then the email will go thru to its destination however it will not pick up and fill in any of the data from the form to the email. It seems to be a syntex problem on my end. Any thoughts.
 
you're not closing your string properly

Code:
ObjSendMail.Subject = "A message from your Contacts Page from " & name[s] &[/s]

should be

Code:
ObjSendMail.Subject = "A message from your Contacts Page from " & name

As far as the other items, change the "method" in your form to method="POST" and use request.form instead of request.querystring - if it still doesn't work, re-post what you have done and I'll take a look again.





TIP: trying googling the answer before posting, you'll find that more times than not someone else somewhere has had the same request and posted an answer online.
----
I have recently been semi-converted to ensuring all my code (well most of it) works in both javascript and non-javascript enabled browsers
 
vicvirk,

I made your change I am not getting an error message the email is coming thru. However the form variables are not populating. I have also made the changes you requested. I have included the new code below.


<%
Dim ObjSendMail
Dim iConf
Dim Flds

set reg = New RegExp
reg.Pattern = "^[A-Za-z0-9\._\-]+@([A-Za-z0-9\._\-]+\.)+[A-Za-z0-9\._\-]+$"
set m = reg.Execute(Request.Form("client_email"))

name = Request.Form("client_name")
senderemail = Request.Form("client_senderemail")
message = Request.Form("client_message")
contactway = Request.Form("client_contactway")
contacttime = Request.Form("client_contacttime")

Set ObjSendMail = Server.CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")
Set Flds = iConf.Fields

Flds(" = 1

'**** Path below may need to be changed if it is not correct
Flds(" = "c:\inetpub\mailroot\pickup"
Flds.Update

Set ObjSendMail.Configuration = iConf
ObjSendMail.To = "webmaster@jwcsconsultingservice.com"
ObjSendMail.Subject = "A message from your Contacts Page from " & name
ObjSendMail.From = "contactform@junkcarsfl.com"

' we are sending a text email.. simply switch the comments around to send an html email instead
ObjSendMail.HTMLBody = "<html><head><title>Contact Letter</title></head><body><br>" &_
"This is the body of the message." &_
"</body></html>"
'ObjSendMail.TextBody = "this is the body"

ObjSendMail.Send
response.redirect("thanks.html")

Set ObjSendMail = Nothing
%>
 
You have to populate the variables into the message, as per below for the main body....

Code:
ObjSendMail.HTMLBody = "<html><head><title>Contact Letter</title></head><body><br>[b]"  & message & "[/b]</body></html>"

TIP: trying googling the answer before posting, you'll find that more times than not someone else somewhere has had the same request and posted an answer online.
----
I have recently been semi-converted to ensuring all my code (well most of it) works in both javascript and non-javascript enabled browsers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top