troubleshooting Question

Form generates error and no attachment

Avatar of TrueBlue
TrueBlueFlag for United States of America asked on
ASP
3 Comments1 Solution514 ViewsLast Modified:
Hi!

Our web hosting company stopped supporting CDONTs.
So we are trying to implement CDOSYS.
Our original form used CDONTs and ASPUpload to send an attachment.
As you can see we are still using the ASPUpload not sure if needed or not?
Currently, using FF version 19.0.2 an email is generated with no attachment.
The attachment is however stored in the upload directory on the server.
Using IE 10 we just get an error '8004020f' /sendeform.asp, line 99
Line 99 is     ObjSendMail.Send

So obviously we have a problem with this line...

  if len(Filename) > 0 then
      objSendMail.AddAttachment Server.MapPath(Upload.Form("FilePath")) & "\" & Filename
  end if

Not sure what else.

Any specific code corrections would greatly appreciated.

I am sure the server.mappath is correct not sure what equivalent of upload.form("FilePath")
is in CDOSYS
.
Here is our current attempt:

<%@ Language=VBScript%>
<%Response.buffer=true%>
<%
sAllow = "bmp,doc,docx,gif,jpg,pdf,png"
Set Upload = Server.CreateObject("Persits.Upload")

' Limit file size to 100000 bytes, throw an exception if file is larger
Upload.SetMaxSize 100000, True
Upload.SaveToMemory

 For Each File in Upload.Files
      Ext = Lcase(Right(strFileName, 3))
      strFileName = Lcase(File.FileName)

        'test=Server.MapPath(Upload.Form("FilePath") & "\" & strFilename)
        'response.write test ' just for testing
        'response.end() ' just for testing
      
    If instr(sAllow, Ext) Then
      File.SaveAs(Server.MapPath(Upload.Form("FilePath") & "\" & strFilename))
      End If             
 Next

%>
<!-- Include file for CAPTCHA form processing -->            
<!-- #include file="CAPTCHA/new_CAPTCHA_process_form.asp" -->
<%
If "" & Upload.Form("EmailAddress") <> "" Then
    'blnCAPTCHAcodeCorrect = Upload.Form("CAPTCHA_Postback")
    'response.write blnCAPTCHAcodeCorrect
    'response.write Upload.Form("EmailAddress")
    'response.end

    If blnCAPTCHAcodeCorrect <> True then
      Session("Name") = Upload.Form("Name")
      Session("EmailAddress") = Upload.Form("EmailAddress")
      Session("DaytimePhone") = Upload.Form("DaytimePhone")
      Session("Subject") = Upload.Form("Subject")
      Session("StreetAddress") = Upload.Form("StreetAddress")
      Session("City") = Upload.Form("City")
      Session("State") = Upload.Form("State")
      Session("ZipCode") = Upload.Form("ZipCode")
      Session("Message") = Upload.Form("Message")
      'response.write Session("Message")
      'response.end
      Response.Redirect "contact-us.asp?err=captcha"
    Else
   
    strBody = "<!DOCTYPE HTML PUBLIC ""-/W3C//DTD HTML 4.0 Transitional//EN"">" _
         & "<html>" _
         & "<head>" _
         & "<title>" & Upload.Form("Subject") & "</title>" _
         & "<meta http-equiv=Content-Type content=""text/html; charset=iso=8859-1"">" _
         & "</head>" _
         & "<body bgcolor=""#FFFF99"">" _
         & "<h2>" & Upload.Form("Subject") & "</h2>" & "<BR>" _
         & "<p>" _
         & "Name: " & Upload.Form("Name") & "<BR>" _
         & "IP Address: " & Request.ServerVariables("REMOTE_HOST") & "<BR>" _
         & "Daytime Phone No: " & Upload.Form("DaytimePhone") & "<BR>" _
         & "Address: " & Upload.Form("StreetAddress") & "<BR>" _
         & "City: " & Upload.Form("City") & "<BR>" _
         & "State: " & Upload.Form("State") & "<BR>" _
         & "Zip Code: " & Upload.Form("ZipCode") & "<BR>" _
         & "Message: " & Upload.Form("Message") & "<BR>" _
         & "</p>" & "<BR>" _
         & "</body>" & "<BR>" _
         & "</html>" & "<BR>"
         
    Dim ObjSendMail
    Set ObjSendMail = CreateObject("CDO.Message")
   
  ' This section provides the configuration information for the remote SMTP server.
    ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 'Send the message using the network (SMTP over the network).
    ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") ="mail.mydomain.com"
    ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 587
    ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False 'Use SSL for the connection (True or False)
    ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60

  ' If your server requires outgoing authentication uncomment the lines below and use a valid email address and password.
   ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 'basic (clear-text) authentication
   ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") ="techserv@mydomain.com"
   ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") ="xxxxxx"
   
    ObjSendMail.Configuration.Fields.Update
  ' End remote SMTP server configuration section==

  ' Set the properties of the object
    ObjSendMail.Subject = Upload.Form("Subject")
    ObjSendMail.From = Upload.Form("EmailAddress") 'specify senders address
    ObjSendMail.To = "techserv@mydomain.com"
  ' ObjSendMail.Cc = "sales@mydomain.com"
  ' Response.write Server.MapPath(Upload.Form("FilePath")) & "\" & Filename
    if len(Filename) > 0 then
      objSendMail.AddAttachment Server.MapPath(Upload.Form("FilePath")) & "\" & Filename
    end if
    ObjSendMail.HTMLBody = strbody
   
    ObjSendMail.Send
    Set ObjSendMail = Nothing

    Response.Redirect("thankyou.htm")
    If Err <> 0 Then
      Response.Write "Error encountered: " & Err.Description
    End If
   
    End If
   Else %>
   <script language="JavaScript" type="text/javascript">javascript: window.history.back(-1)</script>
 <% End IF %>
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros