4 Replies - 5584 Views - Last Post: 21 August 2012 - 04:34 AM Rate Topic: -----

#1 php_lover  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 15-August 12

What's wrong with this ASP contact form code ?

Posted 15 August 2012 - 05:36 PM

Hello , I am trying to add a simple contact form that sends email to my website in ASP ..

Here is the front-end HTML form ,
<form method="POST" action="contact.asp">
Fields marked (*) are required

<p>Email From:* <br>
<input type="text" name="EmailFrom">
<p>Name:<br>
<input type="text" name="Name">
<p>TelephoneNumber:* <br>
<input type="text" name="TelephoneNumber">
<p>Street1:<br>
<input type="text" name="Street1">
<p>Street2:<br>
<input type="text" name="Street2">
<p>City:<br>
<input type="text" name="City">
<p>County:<br>
<input type="text" name="County">
<p>YourMessage:<br>
<textarea name="YourMessage"></textarea>
<p><input type="submit" name="submit" value="Submit">
</form>
<p>



and here is the back-end form supposed to send the email .. I dont get any email when I check my email box to test it,
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>
<body>
<%
' Website Contact Form Generator 
' http://www.tele-pro.co.uk/scripts/contact_form/ 
' This script is free to use as long as you 
' retain the credit link 

' declare variables
Dim EmailFrom
Dim EmailTo
Dim Subject
Dim Name
Dim TelephoneNumber
Dim Street1
Dim Street2
Dim City
Dim County
Dim YourMessage


' get posted data into variables
EmailFrom = Trim(Request.Form("EmailFrom")) 
EmailTo = "jmartin@gcc.vccs.edu"
Subject = "Contact"
Name = Trim(Request.Form("Name")) 
TelephoneNumber = Trim(Request.Form("TelephoneNumber")) 
Street1 = Trim(Request.Form("Street1")) 
Street2 = Trim(Request.Form("Street2")) 
City = Trim(Request.Form("City")) 
County = Trim(Request.Form("County")) 
YourMessage = Trim(Request.Form("YourMessage")) 


' validation
Dim validationOK
validationOK=true
If (Trim(EmailFrom)="") Then validationOK=false
If (Trim(TelephoneNumber)="") Then validationOK=false
If Not (IsNumeric(TelephoneNumber)) 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 & "TelephoneNumber: " & TelephoneNumber & VbCrLf
Body = Body & "Street1: " & Street1 & VbCrLf
Body = Body & "Street2: " & Street2 & VbCrLf
Body = Body & "City: " & City & VbCrLf
Body = Body & "County: " & County & VbCrLf
Body = Body & "YourMessage: " & YourMessage & VbCrLf


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

if validationOK = true then
response.redirect "error.html" 'your redirect page goes here'
end if

%>




Is This A Good Question/Topic? 0
  • +

Replies To: What's wrong with this ASP contact form code ?

#2 h4nnib4l  Icon User is offline

  • The Noid
  • member icon

Reputation: 1182
  • View blog
  • Posts: 1,677
  • Joined: 24-August 11

Re: What's wrong with this ASP contact form code ?

Posted 16 August 2012 - 12:11 PM

Why aren't you using any ASP.NET? Building that form with ASP controls would make your efforts in code-behind much easier.
Was This Post Helpful? 0
  • +
  • -

#3 Nakor  Icon User is offline

  • Professional Lurker
  • member icon

Reputation: 445
  • View blog
  • Posts: 1,501
  • Joined: 28-April 09

Re: What's wrong with this ASP contact form code ?

Posted 16 August 2012 - 06:34 PM

I think the OP is working with just ASP, not ASP.Net. Unfortunately ASP is before my time.
Was This Post Helpful? 1
  • +
  • -

#4 php_lover  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 15-August 12

Re: What's wrong with this ASP contact form code ?

Posted 19 August 2012 - 05:07 PM

What's wrong with this short ASP code ?? please help .. 10 points !!!?
Please help me figure out what's wrong with this SHORT ASP code for email form?
I am more familiar with PHP .... I am trying to implement a contact form in ASP because the server is only compatible with it .. but when I test it to see if it sends the message to my email address , I dont see anything .. could someone please tell me where I went wrong.

HTML FORM CODE:
html>
<head>
<title>form to email script</title>
</head>
<body>

<div align="center">
<form method="POST" action="form_ac.asp" name="form1">
<table width="75%" border="0" cellspacing="0" cellpadding="0">
<tr> 
<td>name:</td>
<td colspan="2"> 
<input type="text" name="name">
</td>
</tr>
<tr> 
<td>email:</td>
<td colspan="2"> 
<input type="text" name="email">
</td>
</tr>
<tr> 
<td>message:</td>
<td colspan="2"> 
<textarea name="message" cols="40" rows="5"></textarea>
</td>
</tr>
<tr>
<td> </td>
<td colspan="2">
<input type="submit" name="Submit" value="Submit">
<input type="reset" name="Reset" value="Reset">
</td>
</tr>
</table>
</form>
</div>
</body>
</html>

Call this page form_ac.asp (the ac is short for acquire as it will be receiving values)

<%@ Language="VBscript" %>
<% Option Explicit %>

<html>
<head>
<title>Message Sent</title>
</head>

<body>
<%
'declare the variables that will receive the values 
'receive the values sent from the form and assign them to variables
'note that request.form("name") will receive the value entered into the textfield
'called name, and so with email and message
Dim name, email, message, NewMailObj
name=request.form("name")
email=request.form("email")
message=request.form("message")

'create the mail object and send the details
Set NewMailObj=Server.CreateObject("CDONTS.N
NewMailObj.From = "alicew_b@hotmail.com"
NewMailObj.To = "alicew_b@yahoo.com"
NewMailObj.Subject = "New message sent.." 
NewMailObj.Body = "the name you entered was " & name & _
"<br>the email was " & email & _
"<br>the message was " & message

'you need to add the following lines FOR the mail to be sent in HTML format
NewMailObj.BodyFormat = 0 
NewMailObj.MailFormat = 0 
NewMailObj.Send
'Close the email object and free up resources 
Set NewMailObj = nothing
Response.write "The email was sent."
%> 

</body>
</html>


Was This Post Helpful? 0
  • +
  • -

#5 Nakor  Icon User is offline

  • Professional Lurker
  • member icon

Reputation: 445
  • View blog
  • Posts: 1,501
  • Joined: 28-April 09

Re: What's wrong with this ASP contact form code ?

Posted 21 August 2012 - 04:34 AM

You should probably contact the hosting provider and work with them to get your mail function working. They should know how to get an email function working with their system.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1