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

Why doesn't this work? 1

Status
Not open for further replies.

rogerte

Programmer
Nov 9, 2001
164
0
0
GB
Can someone help? I have an asp contact page which works properly, except that the messagebox does not display, and I cannot see an obvious reason why.

Thanks

------------------------------------
Code:
<html>
<head>

</head>
<body>
<form method=Post action="">
<p class="leftNormalText">Your name</p>
<input type="text" name="t1" size="20"><br>
<p class="leftNormalText">Your email</p>
<input type="text" name="t2" size="20"><p>
<p class="leftNormalText">Your message</p>
<textarea rows="4" name="st" cols="50"></textarea><p>
<input type=submit value=Submit></form>

<%
Dim JMail, intComp, strReferer, strServer, strClientIP, strServerIP, blnSpam
Dim stname,st
Dim t1name,t1,t2name,t2

t1name = "Sender's name"
t1 = Request.Form("t1")
t2name = "Sender's email"
t2 = Request.Form("t2")
stname = "Message"
st = Request.Form("st")

Set JMail = Server.CreateObject("JMail.SMTPMail")
strReferer = request.servervariables("HTTP_REFERER")
strServer = Replace(request.servervariables("SERVER_NAME"),"[URL unfurl="true"]www.","")[/URL]
strClientIP = request.servervariables("REMOTE_ADDR")
strServerIP = request.servervariables("LOCAL_ADDR")

'spam checker
intComp = inStr(strReferer, strServer)
If intComp > 0 Then
blnSpam = False
Else
' Spam Attempt Block
blnSpam = True
End If

JMail.ServerAddress = "smtp." & strServer & ":25"
JMail.AddRecipient "info@club.org.uk"

JMail.Sender = "info@club.org.uk"

JMail.Subject = "Website Contact Form"

JMail.Body = t1name & vbcrlf&_
t1 & vbcrlf&_
t2name & vbcrlf&_
t2 & vbcrlf&_
stname & vbcrlf&_
st & vbcrlf&_
now()

if NOT blnSpam Then
  JMail.Execute
  strResult = "Mail Sent."
Else
  strResult = "Mail Not Sent."
End If

Response.Write("<" & "script language=VBScript>") 
Response.Write("MsgBox """ & strResult & """<" & "/script>") 
Set JMail = Nothing 
%>

</body>
</html>
------------------------------------
 
Why not some in line with this:

Code:
if NOT blnSpam Then
  JMail.Execute
  ' error handling (if the mail is actually sent)
  'if error
  ' message
  ' else


  Set JMail = Nothing

  response.write "Mail Sent."
  response.write "<input type=button onclick=location.href='nextpage.asp'>" 
  response.end

Else
  Set JMail = Nothing

  response.write "Mail Not Sent."
  ' info + [OK] button
  response.wrire.end
End If
 
>which works properly, except that the messagebox does not display
Though I may not favor use of bare script lines like that, the reason why it won't display is probably the user just use non-ie browser to load the page. Replace the two lines with these see if it displays.
[tt]
Response.Write("<" & "script language=""javascript"">")
Response.Write("alert(""" & strResult & """);<" & "/script>")
[/tt]
 
Thanks for the replies - The problem, as tsuji correctly identified, was Firefox!

However I have tried both suggestions and in both cases, when the page first loads the "mail not sent" message appears.

I'm sorry if this is obvious stuff, but I am new to ASP having inherited a couple of old websites to support because I had done a bit of HTML in the past
 
mmmm, try
intComp = inStr( strServer, strReferer)
 
That way causes the "Mail Sent" message to be displayed and a blank email to be sent!
 
mmmm i was under the impression that you always had an email not send message. That is based on the blnSpam check, and is set by the comparison of servervariables.

having a closer look at the program: after your form, the script does not stop!.

Code:
if request.servervariables("REQUEST_METHOD")<> "POST" then
' we came here after a submit
%> 
<form method=Post action="thisscript.asp">
etc
<input type=submit value=Submit>  
</form>

<%
else

Dim JMail, intComp, strReferer, strServer, strClientIP, 
t1name = "Sender's name"
t1 = Request.Form("t1")
t2name = "Sender's email"
t2 = Request.Form("t2")
stname = "Message"
st = Request.Form("st")

Set JMail = Server.CreateObject("JMail.SMTPMail")
strReferer = request.servervariables("HTTP_REFERER")
strServer = Replace(request.servervariables("SERVER_NAME"),"[URL unfurl="true"]www.","")[/URL]
strClientIP = request.servervariables("REMOTE_ADDR")
strServerIP = request.servervariables("LOCAL_ADDR")

'spam checker
intComp = inStr(strReferer, strServer)
If intComp > 0 Then
blnSpam = False
Else
' Spam Attempt Block
blnSpam = True
End If

JMail.ServerAddress = "smtp." & strServer & ":25"
JMail.AddRecipient "info@club.org.uk"

JMail.Sender = "info@club.org.uk"

JMail.Subject = "Website Contact Form"

JMail.Body = t1name & vbcrlf&_
t1 & vbcrlf&_
t2name & vbcrlf&_
t2 & vbcrlf&_
stname & vbcrlf&_
st & vbcrlf&_
now()

if NOT blnSpam Then
  JMail.Execute
  strResult = "Mail Sent."
Else
  strResult = "Mail Not Sent."
End If

Response.Write("<" & "script language=""javascript"">") 
Response.Write("alert(""" & strResult & """);<" & "/script>") 
Set JMail = Nothing 
end if
%>
 
Thanks that works!.

In the meantime I had come to the same conclusion and had "kludged" it by surrounding the routine with:

If len(t2) > 0 Then
Set JMail = Server.CreateObject("JMail.SMTPMail")
.
.
.
Set JMail = Nothing
End If

Many thanks for your help
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top