Forum Moderators: open
I moved your question over here to the Microsoft (.NET and ASP) forum -- it's a better place for the conversation and I am pretty much a total hack with ASP anyway.
I'm sure someone will come along soon with some help.
The form code is: <input type="file" name="file">. You will also need to andd ENCTYPE="multipart/form-data" to your <form> field. Because of the ENCTYPE attribute, you will have to change from the standard Response.Form to Upload.Form. Upload.Form acts in the exact same way as Response.Form when it comes to taking in variables from the form.
Attaching the file to the email depends on which way you are creating the email in ASP, using CDONTS:
objMail.AttachFile Server.MapPath("/files/file.txt")
The thing is that you need to process the form attached file before you can hope of sending it as an attachment in your ASP mail. It needs to come from the users machine to your server (via the form processing page) and then from your server as the email attachment.
<added>Enctype description</added>
I'm not at all well versed in ISAPI, but the article talks about using the associated http packet which describes the mime-type of the server request. If I read it correctly, you can use an extention to parse the request. I'm still getting to grips with the content of the article, but it seems to highlight a superior performance enhancement.
The following is the code I am using in my "mail.asp" file. I am having trouble figuring out where to put "Upload.Form" and "objMail..." as mentioned by BlobFisk.
<%@ Language=VBScript %>
<%
Dim MyMail
Dim MyField
for each MyField in Request.Form
if (MyField <> "To") and (MyField <> "From") and (MyField <> "Subject") and (MyField <> "Redirect") and (MyField <> "Submit") then
myBody = myBody + MyField + ":" + Request.Form(MyField) + Chr(13)
end if
next
Set MyMail = Server.CreateObject("CDONTS.NewMail")
MyMail.To = Request("To")
MyMail.Subject = Request("Subject")
MyMail.From = Request("From")
MyMail.Body = myBody
MyMail.Send
Set myMail = Nothing
Response.Redirect Request("Redirect")
%>
All other code tips from Blob were already utilized in the form code. So I think my problems are coming from the email code (mail.asp). Any further advice?
rasta_richie:
You need to split the problem into two parts.
(1) Retrieving the file and saving it to your server.
(2) Attaching the file to your email.
As aspdaddy said, it's vital to find out if your hosting service allows file uploads (many have issues with it in terms of bandwidth useage and opening themselves up to malicious files).
In your asp page you will need to take in all the variables from your form, including your file. You will then need to save the file to you server.
Once this is done, you can then begin formatting your mail and attaching the above saved file. Since you know the filename and the location where it was saved, this should be straightforward enough.
HTH