![]() |
|
|
|||||||
![]() |
|
|
Thread Tools | Rate Thread |
|
|
PM User | #1 |
|
Regular Coder ![]() Join Date: Nov 2005
Posts: 335
Thanks: 25
Thanked 1 Time in 1 Post
![]() |
ASP form with attachment query
Hello
I have the following script which sends an email to the Webmaster from an online form. Code:
<%
Dim conn,rs,SQL,myMail,name,email,subject,message
'Open MS Access database, store form field values
set conn=Server.CreateObject("ADODB.Connection")
conn.Open "driver={Microsoft Access Driver (*.mdb)};DBQ=D:\myForm.mdb;"
name = Request.Form("name_txt")
email = Request.Form("email_txt")
subject = Request.Form("subject_txt")
message = Request.Form("message_txt")
SQL="INSERT INTO users (name, email, subject, message) VALUES ('" & _
name & "', '" & email & "','" & subject & "', '" & message & "')"
conn.Execute(SQL)
conn.Close
Set conn=Nothing
Set myMail=CreateObject("CDO.Message")
myMail.Subject="Your message to my_site"
myMail.From="info@my_site.com"
myMail.To= ("" & email)
myMail.BCC="admin@whoever.com."
myMail.HTMLBody="Your message." & vbcrlf & vbcrlf & _
"Please do not reply to this email" & vbcrlf & "<br><br>" &_
"<B><font face='verdana' size='2' color='navy'>Full name:</font></B> " & name & vbcrlf & "<br>" &_
"<B><font face='verdana' size='2' color='navy'>Email</font></B>: " & email & vbcrlf & "<br>" &_
"<B><font face='verdana' size='2' color='navy'>Subject</font></B>: " & subject & vbcrlf & "<br>" &_
"<B><font face='verdana' size='2' color='navy'>Message</font></B>: " & message & vbcrlf
myMail.Send
set myMail=nothing
If Err.Number <> 0 then
Response.Write "&server_mes=fail"
Response.End
else
Response.Write "&server_mes=ok"
End if
%>
One is to add a form field to allow the site visitor to send attachments (Word docs and, maybe, images), and the other is to allow a 'thank you' to the site visitor once the form has been send. Do I simply add: myMail.AddAttachment "c:\mydocuments\whatever.doc" and what about the 'thank you' message, please? How would I display that? Many thanks. Steve |
|
|
|
|
|
PM User | #2 |
|
Senior Coder ![]() Join Date: Feb 2009
Location: Snohomish, WA
Posts: 4,061
Thanks: 18
Thanked 660 Times in 652 Posts
![]() ![]() |
Are they attaching things that *ALREADY* have been uploaded from their local machines to the server?
Or do you mean they need to be able to upload those files that will be attached?? If the latter, you are in for a rude surprise. Most of your code will need rework, because you can no longer use Request.Form() to get form fields. You must, instead, rely upon whatever upload component you will use to do this for you.
__________________
"Old age and cunning win out over youth and enthusiasm every time." |
|
|
|
|
|
PM User | #3 |
|
Regular Coder ![]() Join Date: Nov 2005
Posts: 335
Thanks: 25
Thanked 1 Time in 1 Post
![]() |
Hello Old Pedant
Thanks for your reply. No, the files will not already have been uploaded. The site visitor will need to be able to upload files from the hard drive on their own computer or files on a flash drive in a café, or from a network, into the 'attachment' field of my form. Cheers Steve |
|
|
|
|
|
PM User | #4 |
|
Senior Coder ![]() Join Date: Feb 2009
Location: Snohomish, WA
Posts: 4,061
Thanks: 18
Thanked 660 Times in 652 Posts
![]() ![]() |
So the only way to do this is to indeed use <input type=file> in your <form>, and then use an upload component on the server.
If possible, use an ActiveX component for the uploader. It will be *much* faster and more reliable. But if not possible, then there *are* some free ASP-only (actually, VBScript-only) uploaders out there. http://www.aspin.com is a good place to look for one. The "tricks" to this: (1) You must use enctype="multipart/form-data" in your <form> tag. (2) To get form fields, you must use the method supplied by the uploader component in place of Request.Form. Find your upload component, first, then carefully read its docs. If you are using a hosting service, check with them to see if they offer an upload component as part of your hosting. I use GoDaddy, and they include one of the best even in their $5 a month plan.
__________________
"Old age and cunning win out over youth and enthusiasm every time." |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Rate This Thread | |
|
|