Thursday, August 13, 2009

Send Email using ASP from a Web Form in GoDaddy

I'm not really fond of GoDaddy, just like I'm not fond of WalMart, but I still shop there. When it comes to cheap hosting, especially in a combined ASP/PHP/.Net environment, they're pretty much it. For less than $10 a month I can get 25 MySQL databases, 5 SOL databases, and unlimited top level domains. Can't be beat, or at least I couldn't find a place to beat it after wasting about hours of my life looking around before picking GoDaddy as my solution.

So I've been moving some of my sites over. Why pay $5 a month (which is still cheap) when I can get hosting for pennies? I mean, $5 isn't much, but when you're hosting 11 sites, it adds up.

Many of the sites I host use contact forms or confirmation forms, or some other form that needs to send out an email. Simple enough, but I spent a good three hours this morning figuring out how to do it on GoDaddy, and not for the reason you think.....

Before I get to that, here's the code:

sendUrl="http://schemas.microsoft.com/cdo/configuration/sendusing"
smtpUrl="http://schemas.microsoft.com/cdo/configuration/smtpserver"

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

' Create and send the mail
Set objMail=CreateObject("CDO.Message")

' Use the config object created above
Set objMail.Configuration = objConfig
objMail.From = "sender@coolexample.com"
objMail.To = "recipient@coolexample.com"
objMail.Subject = "subject"
objMail.TextBody = "body"
objMail.Send

Set objSendMail = Nothing
Set objConfig = Nothing

Replace the hardcoded values for subject, from, to etc. with your own values. Bear in mind GoDaddy will only send 250 messages a day, so if you need to do more, you'll have to come up with some other solution.

Now here's the kicker. Two kickers, really:

The first is GoDaddy doesn't allow detailed error messages for classic ASP. All you get is a 500 Internal Server Error. I wasted a good bit of the three hours trying to figure out how to turn on errors but came up with nada. So good luck troubleshooting your ASP code....

And this is related to the above: I couldn't get the damn thing to work (and I couldn't see the error). So I ended up stepping through it line by line and guess what the problem was?

GoDaddy doesn't allow you to use a GMail address as a from address.

That's right my friends, Read it again.

So say you have a site with some sort of Send to a Friend thing where you ask for the sender's email, so the message says something like YourFriend@HisEmail.com has sent you a link and the from address is actually the person's email.

Well, if your address happens to be a GMail (and maybe other free mail apps, I didn't check) you get an error. An error that you can't troubleshoot.

Once I figured that out, the code worked fine, although I had to update some of my forms to change the sent from value so it didn't use the submittor's email address anymore.

1 comment:

Anonymous said...

I didn't hard code the "From e-mail" address and it works fine for me.

Passed the variables from an HTML page to the asp and it works fine.

Perhaps GoDaddy fixed it?

Thanks for your article.