DotDragnet
February 07, 2012, 02:41:50 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: follow us on twitter @dotdragnet
 
   Home   Help Search Login Register  
Pages: [1]   Go Down
  Print  
Author Topic: ASP contact form  (Read 1301 times)
neal
Sr. Member
****
Posts: 300



nealio82
View Profile Awards
« on: March 02, 2010, 10:39:45 PM »

Hi all,

I've recently transferred an ASP site from one host to another for a designer's client. the problem is i know no ASP whatsoever & with my php background i've been trying to find my way through the code.

the new site is being held on fasthosts  shocking

the original contact form didn't work on the new server so tonight i've been trawling through fasthosts documentation & their code examples to try & get something working (even just a hello world email to my inbox would be nice)

we've left the MX records as they were because their email is running through a 3rd party's mail servers & the client wants to keep that as-is.

i've tried the code from their example which fails with a 500 error at the JMail.Execute phase (plenty of commenting out code until it stops breaking then re-adding line by line until it re-breaks has diagnosed that). I'm guessing that's because the outgoing server is set to smtp.domain.co.uk & obviously that address isn't on the fasthosts cluster (as the mx records point elsewhere). i just need to get this working so i can actually populate it with the form submission!

Code:
<%

dim JMail, intComp, strReferer, strServer, strClientIP, strServerIP, blnSpam

Set JMail = Server.CreateObject("JMail.SMTPMail")

strReferer = request.servervariables("HTTP_REFERER")
strServer = Replace(request.servervariables("SERVER_NAME"),"www.","")
strClientIP = request.servervariables("REMOTE_ADDR")
strServerIP = request.servervariables("LOCAL_ADDR")

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

JMail.ServerAddress = "smtp." & strServer & ":25"
JMail.Sender = "website@" & strServer
JMail.Subject = "JMail Example" & " Sent @ " & now()
JMail.AddRecipient "my.email@mydomain.net"


JMail.Body = "This test mail sent from: " & strServerIP & " using the JMail component on the server."
JMail.Priority = 3
JMail.AddHeader "Originating-IP", strClientIP

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


set jmail=nothing

%>

the site's original sendmail code is here, but it just says "message could not be sent"

Code:
<%



'----function that removes html tags----------
   Function RemoveHTML( strText )
Dim RegEx
Set RegEx = New RegExp
RegEx.Pattern = "<[^>]*>"
RegEx.Global = True
RemoveHTML = RegEx.Replace(strText, "")
End Function
'---------------------------------------------
   
'------defining script vars-------------------
   Dim mailObj, mailCfg, myBody, fld, subj, mail_from, mail_to, smtp_server, smtp_port, plain_text

Dim RegEx
    set RegEx = New RegExp
'--------------------------------------------


'----Settings-----------
subj = "Web Site Information Request"
mail_from = "website@domain.com"
mail_to = "my.email@mydomain.net"
smtp_server = "localhost"
smtp_port = 25
plain_text = "false"

'------getting data sent by site (filtering configuration data)------------
   For Each fld in Request.Form
      If Request.Form(fld) <> "" and _
      fld <> "mail_to" and _
  fld <> "smtp_server" and _
  fld <> "smtp_port" and _
  fld <> "plain_text" and _
  fld <> "mail_from" and _
      fld <> "mail_subject" Then
         myBody = myBody & vbCRLF & "   <b>" & fld & "</b> :<br/> " & Trim(Request.Form(fld)) & "<br/>"
      End If
   Next
'---------------------------------------------------------------------------

'----------setting conf data------------------------------------------------
On Error Resume Next
Set myMail = CreateObject("CDO.Message")
myMail.Subject = subj
myMail.From =mail_from
myMail.To = mail_to

'--------if plain text is set to true removing html---------------------------------------
if plain_text = "true" then

myMail.TextBody = RemoveHTML(myBody)

'-------otherwise composing message body--------------------------------------------------
else myMail.HTMLBody = "<html><body>" & myBody & "</body></html>"

end if


'----------setting configuration params for smtp----------------------------------------------------------------------------------
myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 1
myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = smtp_server
myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = smtp_port
myMail.Configuration.Fields.Update
'---------------------------------------------------------------------------------------------------------------------------------
myMail.Send '---------------sending message
 
   If Err = 0 Then
   Response.Write("The message has been sent, thank you") 'if there the message is sent return 1 to flash
   'Response.Redirect "success.asp"
   Else
   Response.Write("Message could not be sent") 'otherwise return 0
   End If
   
%>

the fasthosts documentation also says you can use CDO in ASP but the JMail approach is preferred

all these criteria are satisfied, the email is sent from website@domain.com (for which i have also set up a mailbox just in case they check the existence of the mailbox itself rather than just the domain living on their server)

Quote
  Fasthosts redirects all web based mail to an SMTP Filter System.
  Emails must have either a valid "from" or "to" address which is a
  mailbox hosted with Fasthosts. Any email that does not fulfil this
  criterion will not be delivered. If you are sending email to a customer
  who has given you his email address, you need to use the domain
  name of your website.
• Fasthosts' SMTP Filter System rate limits outgoing mail from any
  domain, to prevent bulk emailing. Our limits are set to allow normal
  form-based email activity to pass unhindered, but stop any
  persistent attempt to send bulk mail.
• The SMTP Filter System will prevent mass emailing (spam).
  All attempts to send bulk emails are logged and may result in the
  unfortunate suspension of your website, in accordance with our
  misuse policies.


any help would be fantastic, because i'm at a bit of a loss with this! for starters, is there any kind of error reporting i can turn on like with php?

cheers smile
Logged

sig edited due to migrating from .net
samhs
Administrator
Hero Member
*****
Posts: 1669



View Profile WWW Awards
« Reply #1 on: March 02, 2010, 11:24:18 PM »

Your 500 error should be telling you what the issue is, unless you're using IE and have friendly errors turned on in Internet Settings.

Try this code:

Code:

recipient = "you@yourdomain.com"
fromname = "Your Website"
from = "yourwebsite@yourdomain.com"
title = "An email from your website"
body = "<h1>Yay - it worked!</h1>"

Set oCdoMail = Server.CreateObject("CDO.Message")
Set oCdoConf = Server.CreateObject("CDO.Configuration")

sConfURL = "http://schemas.microsoft.com/cdo/configuration/"

with oCdoConf
.Fields.Item(sConfURL & "sendusing") = 2
.Fields.Item(sConfURL & "smtpserver") = "smtp.server.com" 'Enter your SMTP server address here
.Fields.Item(sConfURL & "smtpserverport") = 25

.Fields.Update
end with

with oCdoMail
.From = fromname & "<" & from & ">"
.To = recipient
.Subject = title
.TextBody = body
.HTMLBody = replace(body,vbcrlf, "<br />")
.Configuration = oCdoConf
.Send
end with

Set oCdoConf = Nothing
Set oCdoMail = Nothing

It doesn't use jMail which will probably help.
Logged

Loose adj a not held together; not fastened or firmly fixed in place
Lose verb to misplace something. To fail to keep or obtain something, especially because of a mistake, carelessness, etc.
---
Blog: www.ohwrite.co.uk
Twitter: www.twitter.com/samhs
Jeep Stone
Hero Member
*****
Posts: 906



View Profile WWW Awards
« Reply #2 on: March 03, 2010, 09:02:33 AM »

This is a blast from the past. The number of times I've had code with Farcehosts that won't run because they stop supporting a certain script or remove permissions, is laughable.

Sam's code looks spot on there though - good luck!
Logged

spannaa
Full Member
***
Posts: 203



Spannaa
View Profile WWW Awards
« Reply #3 on: March 03, 2010, 09:35:30 AM »

we've left the MX records as they were because their email is running through a 3rd party's mail servers & the client wants to keep that as-is.


This may be the problem.

Email must be sent to, or from, an email address hosted by Fasthosts. An email address hosted by Fasthosts is not the same as a domain name hosted by Fasthosts. If your domain's MX record points to another email provider, it will not count as being hosted by Fasthosts.


You can't send email from web scripts using the 3rd party servers either!

All outbound email must be routed through our outgoing email servers or it will not be delivered, it is not possible to send email from a script directly to a third party SMTP server.
« Last Edit: March 03, 2010, 10:47:26 AM by spannaa » Logged
neal
Sr. Member
****
Posts: 300



nealio82
View Profile Awards
« Reply #4 on: March 04, 2010, 09:51:17 AM »

cheers for the replies guys,

i'll have a chat with their tech support & try sam's code.

otherwise i'll have to build a php script, put in as much spam protection as possible and host it on another server that will allow sending through a different domain.
Logged

sig edited due to migrating from .net
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF | SMF © 2006-2008, Simple Machines Valid XHTML 1.0! Valid CSS!