Thread: Add attachment

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2004
    Posts
    19
    Rep Power
    0

    Add attachment


    Hi

    I have a simple working contact form.

    Code:
    <form method="post" action="process.asp" name="myform">
                                    <label for="Name">Name:</label>
                                    <input type="text" name="Name" id="Name" />
                                    
                                    <label for="Email">Email:</label>
                                    <input type="text" name="Email" id="Email" />
                                    
                                    <label for="Email">Telephone:</label>
                                    <input type="text" name="Telephone" id="Telephone" />
                                    
                                                                    
                                    <label for="Message">Message:</label><br />
                                  <textarea name="Message" rows="40" cols="20" id="Message"></textarea>
                                    <div>
                                    <input type="image" src="assets/img/sendBtn.png" name="submit" value="Submit" class="submit-button" />
                                    </div>
                              </form>
    The asp:

    Code:
    Set ObjSendMail = CreateObject("CDO.Message")
      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") =""
      ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
      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
      ObjSendMail.Configuration.Fields.Update
      ObjSendMail.To      = "myemail@email.com"
      ObjSendMail.Subject = "Query"
      ObjSendMail.From    = Session("email")
      ObjSendMail.TextBody= messageBody
      
      ObjSendMail.Send
      Set ObjSendMail = Nothing
      
      Response.Write("Email has been sent")
    I want the user to have the facility of uploading a word document.

    I add this line here:
    Code:
    ObjSendMail.From    = Session("email")
      ObjSendMail.TextBody= messageBody
      ObjSendMail.AddAttachment Request.Form("rob")
    i add this to the html form:
    Code:
    <label for="Email">CV:</label>
                                    <input type="hidden" name="rob" value="100" />
    								<input name="file" type="file" />
    The form has stopped submitting and produces the error:
    Code:
    CDO.Message.1 error '800c000d' 
    
    Unknown Error 
    
    /process.asp, line 29
    line 29 is this:
    Code:
    ObjSendMail.AddAttachment Request.Form("rob")
    Can anyone spot what i am missing here please?

    Thanks
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2010
    Posts
    15
    Rep Power
    0
    what you have done will not work.

    When you upload a file you must change the form code to enctype = multipart

    see here for tutorial :

    http://www.asp101.com/resources/aspupload.asp

    you must upload the file to a place on the server. Then to add the attachment you must use the file path to that location.

    see example code here:

    http://www.paulsadowski.com/WSH/cdo.htm
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2004
    Posts
    19
    Rep Power
    0
    I have managed to get this working now but i have a slight problem...

    I am using the Persits.Upload component as i found out that it is provided by my hosting company.

    Great i can now upload and send attachments via email, but because i am using

    Code:
    ENCTYPE="multipart/form-data"
    the request.form("name") and request.form("email") are blanked out so i dont know who is emailing me the attachments.

    When i dont use the entype in the form the request.form fields are populated.

    I know its something simple i am missing here but i cant seem to work out what it is can anyone advise please?
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2010
    Posts
    15
    Rep Power
    0
    The Persits website has a help area where people can get assistance on how to use that component.

IMN logo majestic logo threadwatch logo seochat tools logo