Go Back   CodingForums.com > :: Server side development > ASP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Old 11-03-2009, 05:05 PM   PM User | #1
SteveH
Regular Coder

 
Join Date: Nov 2005
Posts: 335
Thanks: 25
Thanked 1 Time in 1 Post
SteveH is an unknown quantity at this point
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
%>
I would now like to add two functions:

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
SteveH is offline   Reply With Quote
Old 11-04-2009, 06:23 AM   PM User | #2
Old Pedant
Senior Coder

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Location: Snohomish, WA
Posts: 4,061
Thanks: 18
Thanked 660 Times in 652 Posts
Old Pedant will become famous soon enoughOld Pedant will become famous soon enough
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."
Old Pedant is offline   Reply With Quote
Old 11-04-2009, 10:14 AM   PM User | #3
SteveH
Regular Coder

 
Join Date: Nov 2005
Posts: 335
Thanks: 25
Thanked 1 Time in 1 Post
SteveH is an unknown quantity at this point
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
SteveH is offline   Reply With Quote
Old 11-04-2009, 08:23 PM   PM User | #4
Old Pedant
Senior Coder

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Location: Snohomish, WA
Posts: 4,061
Thanks: 18
Thanked 660 Times in 652 Posts
Old Pedant will become famous soon enoughOld Pedant will become famous soon enough
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."
Old Pedant is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:45 AM.

Home - Contact Us - Archives - Link to CF - Resources - Top 

Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.