PDA

View Full Version : Help with simple form not emailing


sward
01-15-2010, 01:18 PM
Hi I am trying to get a simple form to work. It is hosted with Godaddy which is always a problem with ANY email issues. I know it has to be something very simple. The form seems to process but never ends up in the inbox. Please help I know you guys get bored with these types of questions but it would be greatly appreciated. I read somewhere that IIS 6.0 no longer acccepts (Cdonts) yet Godaddy uses it in their help example (go figure typical of them)


Note from Godaddy:

Use the following relay server in your ASP.NET 3.5 code:
relay-hosting.secureserver.net
You do not need to provide a user name and password for this relay server.

but they don't tell you where it needs to go in the code.

Here is my asp page

<%

' declare variables
Dim EmailFrom
Dim EmailTo
Dim Subject
Dim Name
Dim Address
Dim City
Dim State
Dim PostCode
Dim Tel
Dim Comments

' get posted data into variables
EmailFrom = Trim(Request.Form("EmailFrom"))
EmailTo = "myemail@myaddress.com"
Subject = Trim(Request.Form("Subject"))
Name = Trim(Request.Form("Name"))
Address = Trim(Request.Form("Address"))
City = Trim(Request.Form("City"))
State = Trim(Request.Form("State"))
PostCode = Trim(Request.Form("PostCode"))
Tel = Trim(Request.Form("Tel"))
Comments = Trim(Request.Form("Comments"))

' validation
Dim validationOK
validationOK=true
If (Trim(EmailFrom)="") 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 & "Address: " & Address & VbCrLf
Body = Body & "City: " & City & VbCrLf
Body = Body & "State: " & State & VbCrLf
Body = Body & "PostCode: " & PostCode & VbCrLf
Body = Body & "Tel: " & Tel & 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
Set Mail=nothing

' redirect to success page
Response.Redirect("thankyou.html")
%>



And form page code: http://www.patmargo.com/index-6.html


<form method="POST" action="contact.asp">
Fields marked (*) are required

<p>Email From:* <br>
<input name="EmailFrom" type="text" size="40" span class="style4" >
<p>Subject: <br>
<input name="Subject" type="text" size="50" span class="style4">

<p>Name:<br>
<input name="Name" type="text" size="40"span class="style4">
<p>Address:<br>
<input name="Address" type="text" size="50" span class="style4">
<p>City:<br>
<input name="City" type="text" size="50" span class="style4"b>
<p>State:<br>
<input type="text" name="State" span class="style4" >
<p>PostCode:<br>
<input type="text" name="PostCode" span class="style4">
<p>Tel:<br>
<input name="Tel" type="text" size="30" span class="style4" >
<p>Comments:<br>
<textarea name="Comments"span class="style4"></textarea>
<p><input type="submit" name="Submit" span class="style4" value="Submit">
</form>

If this is going to take more than a "simple" fix PLEASE let me know.

Old Pedant
01-15-2010, 11:23 PM
(1) The message from GoDaddy mentioned ASP.NET, but you aren't using ASP.NET.
(2) If you are hosted on IIS 7 at GoDaddy, then CDONTS is no longer supported.

In any case, the best thing to do is to stop trying to use unreliable CDONTS.

Try this, instead (which works on at least a half dozen GoDaddy-based sites that I've been involved with):


<%
' I normally put these at the top of the page, but they can be anywhere before the email code:
CONST sendUrl = "http://schemas.microsoft.com/cdo/configuration/sendusing"
CONST smtpUrl = "http://schemas.microsoft.com/cdo/configuration/smtpserver"

... your code ...

' prepare email body text
Dim Body
Body = Body & "Name: " & Name & VbCrLf
Body = Body & "Address: " & Address & VbCrLf
Body = Body & "City: " & City & VbCrLf
Body = Body & "State: " & State & VbCrLf
Body = Body & "PostCode: " & PostCode & VbCrLf
Body = Body & "Tel: " & Tel & VbCrLf
Body = Body & "Comments: " & Comments & VbCrLf

' send email
' Set the mail server configuration
Set objConfig=CreateObject("CDO.Configuration")
objConfig.Fields.Item(sendUrl)=2 ' cdoSendUsingPort
objConfig.Fields.Item(smtpUrl)="relay-hosting.secureserver.net" ' ** FOR GODADDY ONLY **
objConfig.Fields.Update

' Create and send the mail
Set mail=CreateObject("CDO.Message")
' Use the config object created above
Set mail.Configuration = objConfig
' same as with cdonts:
mail.To = EmailTo
mail.From = EmailFrom
mail.Subject = Subject
' this is different:
mail.TextBody = Body ' yoiu would use mail.HTMLBody for HTML email
result = mail.Send ' result will be non-blank if something went wrong

Set mail=nothing
...


One caution: I use this code to send out about 500 email newsletters (takes 20 to 30 minutes) once a month, and occasionally it will "hang" in the middle of all those messages. I've never had it hang when sending only one or two emails, but that doesn't mean it couldn't.

sward
01-16-2010, 12:35 AM
Thank you so much

I had come across another forum that someone had the same issues and Yes they used basically the same coding you just used: Go daddy does not give very good support for coding issues even when they have created the nightmare. Good for your coders though!


Just for others who may be having the same issues The post that also helped me with this problem is here:

Go Daddy and ASP emailing issues (http://www.jeorgethedodo.com/doug/2005_May/cdo_mail_object.asp)

I will come hang out here some and probally send some business your way I always need some coding done and just lost my main guy who use to help me.

Many Thanks You are awesome!

Old Pedant
01-16-2010, 10:19 PM
Actually, GoDaddy is where I got my code from.

http://help.godaddy.com/article/4219

If you go to "support" and just search for "cdo.message" it's answer number two.

There are other articles there that are helpful, as well.

I think it's just a matter of learning *what* to search for, same as using Google. Some search terms work well, some don't.

Old Pedant
01-17-2010, 01:30 AM
Whoops...turns out she *IS* using ASP.NET!!!

And so the ASP code shown here is completely wrong.

This thread probably could be moved to the ASP.NET forum.

sward
01-17-2010, 04:09 PM
Sorry see I still don't seem to know which code I am using where... I'm a mess... You have been very helpful. The code I posted earlier is working...with the added server info .... so I am stoked!