ASP - sending an email response

Permabanned
Joined
24 Dec 2002
Posts
474
Location
Chelmsford, Essex. Bling Bling
I want a basic form on my site with just a name and text box for people to send some feedback through email.

Using this...

Code:
<html>
<body>
<form action="Test.asp" method="post">

<h3>This form sends an e-mail.</h3>
Name:<br>
<input type="text" name="fullname" size="20">
<br>
<textarea rows="10" cols="30" name="bodytext">
</textarea>
<br><br>
<input type="submit" value="Submit">
</form>

<%
dim FromName
dim MainText

FromName = Request.form("fullname")
MainText = Request.form("bodytext")

if FromName <> "" Then
	response.write("Hello " & Request.form("fullname") & "<br>")
	response.write(Request.form("bodytext"))

	Set myMail=CreateObject("CDO.Message")
	myMail.Subject="New Email"
	myMail.From= FromName
	myMail.To="[email protected]"
	myMail.TextBody=MainText
	myMail.Send
	set myMail=nothing
end if
%> 


</body>
</html>

This doesnt generate any errors but neither do any emails appear in my inbox.
Anything im missing here? Im assuming my web space providor (Blueyonder) have this CDO component installed as i dont get a error when its fired off. The response.writes are just there to make sure the form controls are being picked up correctly which they are.
 
Associate
Joined
8 Oct 2005
Posts
97
Location
Bristol
pretty sure the from address has to match the domain its being sent from
otherwise you could send out emails with fake address's

try [email protected] and it should work


meant to say the from part has to be an email address the matches the domain its being sent from


Code:
Set objCDOMail = Server.CreateObject("CDONTS.NewMail")
	objCDOMail.From = "ContactForm@[U]somewhere.co.uk[/U]"
	objCDOMail.To = "you@[U]somewhere.co.uk[/U]"
	objCDOMail.Subject = subject
	objCDOMail.Body = Mailbody
	objCDOMail.Send
	Set objCDOMail = Nothing
 
Last edited:
Associate
Joined
25 Dec 2002
Posts
1,540
Location
South GLOUCESTER
The "from" address doesn't need to be a valid address, it can be anything you like. Your code looks okay and should function. However that is dependant on whether there is a correctly setup SMTP server on your host.

Glad to see you are using CDO(sys) since CDONTS was meant for NT4, although in most cases it will still function, but the usage is slightly different. Also i noticed you are declaring (dim) your variables which is good practice, it does have its advantages when trying to debug sometimes. It is also said that it makes the code more efficient since memory is allocated correctly and on large apps you should see a performance increase. BUT you won't see any of that since you haven't set the option explicit. Put this at the very top of your web page: <% Option Explicit %>

Anyway i can't see anything obviously wrong with your code so that makes me believe the SMTP server is at fault, if existant at all. Although i'm sure CDOSYS would throw an error otherwise, but not certain on that.

You can however specify your own external SMTP server by using the schemes. I do this myself since a lot of our websites are hosted elsewhere, but i prefer to use our own mail server. Mainly so i can debug any problems and also monitor the flow of e-mail from the sites.

Here is a link which shows you how to do it:

http://www.asp101.com/articles/john/cdosmtprelay/default.asp

I've not looked at the code line for line, but at first glance it appears to be okay and since its publised on asp101 it should be good. You will also see how constants are used which is also good practice if you're writing proper VB.

In the example in the link, you can specify the connection details to your external SMTP server. Since you're on blueyonder, i recommend using their own SMTP server; the same one you use for your blueyonder e-mail (if you use it at all). Simply edit the code to include "smtp.blueyonder.co.uk" as your SMTP server and your blueyonder username and password. If you have a business account, they have a better more reliable server you can use, but you must request it since it isn't setup automatically.

Have a shot at that and if it's still not working, i will test your code for you and point out whats wrong.
 
Permabanned
OP
Joined
24 Dec 2002
Posts
474
Location
Chelmsford, Essex. Bling Bling
ok thanks for all that :)

Ive uploaded the page to my webspace, theres no cgi-bin directory there that i can see so ive just dumped the file into the root of htdocs. This is just the basic Blueyonder personal webspace thing so it might not support email stuff i guess.

When i hit submit i get this error:

----
Error 405 Method Not Allowed
The requested method POST is not allowed for URL /test.asp
----

The link to the page is...
http://www.ashleyc.pwp.blueyonder.co.uk/test.asp
 
Associate
Joined
25 Dec 2002
Posts
1,540
Location
South GLOUCESTER
That page is not getting parsed through the asp engine. If you view the source using the browser you can view all the vbscript.

Didn't you mention you managed to display response.writes and form variables?

I was suprised to hear that you had asp working on blueyonders webspace. i always thought it was only supported on their paid hosting. As far as i knew it was static only except for the cgi-bin.
 
Permabanned
OP
Joined
24 Dec 2002
Posts
474
Location
Chelmsford, Essex. Bling Bling
ah ok, that would be it. Yeah i had the response.writes working on my own machine at work but due to firewalls and things i couldnt ftp it to my blueyonder site until i got home. Thats a bummer. Have to see if i can get some decent web space off them with all the hassle theyre having with sky at the moment :) Threaten to cancel everything or something.
 
Associate
Joined
25 Dec 2002
Posts
1,540
Location
South GLOUCESTER
LOL after all that messing about as well!

In my opinion the web side of telewest / virgin has declined over the years. Their internet connections are still reliable and steady, but they have started using traffic shaping on their network to control the priority of certain data and put caps on specific protocols. It hasn't worked out too bad and it was going to happen sooner or later. Atleast they haven't introduced full on caps like the other providers.

As for the hosting side of things; the impression i got was that its pretty much non existant now. I've not seen them advertise upgraded hosting for a while, but i believe its still possible to upgrade via the selfcare panel which still works after the take over. Their business part of their internet services was called workwise. We use it here where i work. Same hardware supplying the internet, but the MAC address exposed to the WAN is fixed so that the IP address don't change. We have been using the same IP from telewest for 4 years now. It has a higher upload speed of 512Kbit, but download is still at 4Mbit, despite constant assurance they're soon offer business customers higher speeds. They did cut their prices to near half though which is good. Part of the workwise 4000 package included an e-mail backup option which consisted of an SMTP server which would accept all e-mail and could then be accessed via pop3. This would have been good for dedundancy if your company only has a single mail server. Having remember about this i enquired about it for them to tell me they no longer offer it. This was after i went through about 5 people, many of them had to ask if i was a telewest or ntl customer! Eventually they put me through to their sales team who tried to sell me MS exchange mailboxes at £5 each! What a load of jokers. We're a company of 60 people soon to be 100 end of this year and one of their sales monkey was trying to presurise me to buy these crap mailboxes which would be totally unmanagable for more than 10 employees.

Not impressed with their recent service at all, but it does keep getting cheaper and the internet connection is worth the money since it has never gone wrong in the 4 years that i have been here and has always given us maximum throughput so can't complain really. Used to be good back in the day when they focused heavily on providing gaming servers, hosting and access. Now they only care about getting residential users to sign up their 3 for 1 package!

Consider hosting the website yourself, or ask some kind member on here if they wouldn't mind hosting the ASP pages on their webspace. Remember you can always post to a file outside of your site, just use response.redirect to take you back in once the script has run.
 
Back
Top Bottom