Good Day Everyone,
I am trying to build a classic .asp form to streamline some of our companies submissons. Can anyone suggest a very basic form or inform me on how I can get the end user to submit an attachment through a form?
I am a bit lost with .asp. I have more experience with other scripting languages but .asp is french to me.
Heres the catch, I do not want to to save to the server. Is it possible to submit the form as an email directly to me with the attachment?
<html><head><title>form to email script</title></head><body><div align="center"><form method="POST" action="formTest_validate.asp" name="form1" enctype="multipart/form-data"><h2>Name</h2><br /><input type="text" name="name"><br /><h2>Email Address</h2><br /><input type="text" name="email"><br /><h2>Message</h2><br /><textarea name="message"></textarea><br /><input type="file" name="File1" runat="server"><br /><input type="submit" name="Submit" value="Submit"><input type="reset" name="Reset" value="Reset"></form></div></body></html>
Here is the validating and email submission.
<%@ Language="VBscript" %><% Option Explicit %><html><head><title>Message Sent</title></head><body><% Dim name, email, message, myMailObj, binaryData name=request.form("name") email=request.form("email") message=request.form("message") binaryData = objUpload("File1").BLOB & ChrB(0) Set myMail=CreateObject("CDO.Message") 'Set NewMailObj=Server.CreateObject("CDONTS.NewMail") 'NewMailObj.From = "youremail@random.com" myMailObj.From = "youremail@random.com" 'NewMailObj.To = "youremail@random.com" myMailObj.To = "youremail@random.com" 'NewMailObj.Subject = "New message sent.." myMailObj.Subject = "New message sent.." 'NewMailObj.Body = "the name you entered was " & name & _ myMailObj.Body = "the name you entered was " & name & _ "<br>the email was " & email & _ "<br>the message was " & messagemyMail.Configuration.Fields.Update set rset = server.createobject("ADODB.RECORDSET") rset.fields.append "File1", 205, LenB(binaryData) rset.open rset.addnew rset.fields(0).AppendChunk binaryData binaryData = rset.fields("File1").value Const cdoContentDisposition = "urn:schemas:mailheader:content-disposition" Const cdoBase64 = "base64" Dim attach : Set attach = myMail.Attachments.Add attach.ContentMediaType = "application/octet-stream" attach.ContentTransferEncoding = cdoBase64 attach.Fields(cdoContentDisposition).Value="attachment;filename=""File1""" attach.Fields.Update Dim oStreamOutput: Set oStreamOutput = attach.GetDecodedContentStream oStreamOutput.Write binData oStreamOutput.Flush myMail.Send set myMail=nothing myMailObj.BodyFormat = 0 myMailObj.MailFormat = 0 myMailObj.Send Set myMailObj = nothing Response.write "The email was sent." %></body></html>
Can someone help? What am I missing? Can you point me in the right direction?
Regards,
-Aaron
p.s. The attachments can be text or image files.