Click to See Complete Forum and Search --> : Problem creating Email Form with Attachment - can anyone help??


ric73
10-11-2006, 04:44 PM
Hello,

I am creating a form that sends an email with some text fields and allows the user to choose a file from his computer and attach it to the email and send it to my web server. I receive the email with all the text fields but the attachement field is just the file location and not the file!

I am using FORM method="post" and I have tried to use enctype="multipart/form-data" with INPUT type="file" but then I do not receive anything at all.

Does my server not support the enctype attribute am I doing something wrong in the ASP code I send:

Sub SendContactEmail()
Dim strFrom
Dim strTo
Dim strSubject
Dim strBody

strFrom = Request.Form("Name") & " <" & ValidateFrom(Request.Form("EMail")) & ">"
strTo = "email@email.com"
strSubject = "Contact"
strBody = _
"Name: " & Request.Form("Name") & vbCrLf & _
"Telephone: " & Request.Form("Telephone") & vbCrLf & _
"EMail: " & Request.Form("EMail") & vbCrLf & _
"Architect: " & Request.Form("Architect") & vbCrLf & _
"Year Built: " & Request.Form("Year") & vbCrLf & _
"Location: " & Request.Form("Location") & vbCrLf & _
"Country: " & Request.Form("Country") & vbCrLf & _
"File: " & Request.Form("filefield") & vbCrLf & _
"Comments: " & Request.Form("Comments") & vbCrLf

EmailText strFrom, strTo, "", strSubject, strBody
End Sub

The form code is as follows without the enctype:

<FORM method="post" class="ContactField">

<DIV class="ContactLabel">Name:</DIV>
<DIV><INPUT type="text" name="Name" class="ContactField" size="20"></DIV>

<DIV class="ContactLabel">Telephone:</DIV>
<DIV><INPUT type="text" name="Telephone" class="ContactField" size="20"></DIV>

<DIV class="ContactLabel">EMail:</DIV>
<DIV><INPUT type="text" name="EMail" class="ContactField" size="20"></DIV>

<DIV class="ContactLabel">Architect:</DIV>
<DIV><INPUT type="text" name="Architect" class="ContactField" size="20"></DIV>

<DIV class="ContactLabel">Year Built:</DIV>
<DIV><INPUT type="text" name="Year" class="ContactField" size="20"></DIV>

<DIV class="ContactLabel">Location:</DIV>
<DIV><INPUT type="text" name="Location" class="ContactField" size="20"></DIV>

<DIV class="ContactLabel">Country:</DIV>
<DIV><INPUT type="text" name="Country" class="ContactField" size="20"></DIV>-->

<DIV class="ContactLabel">Upload Image:</DIV>
<DIV><input type="file" name="filefield" class="ContactField" size="20"></DIV>

<DIV class="ContactLabel">Comments:</DIV>
<DIV><TEXTAREA name="Comments" class="ContactField" scroll="auto" rows="1" cols="20"></TEXTAREA></DIV>

<DIV class="ContactSubmit"><INPUT type="image" src="/images/submit-acc.gif" width="87" height="17" align="middle"></DIV>
<DIV class="ContactNote">NOTE: Your information will never be shared with a third party!</DIV>
</FORM>


I am getting desperate! Can anyone help? THANK YOU

simflex
10-15-2006, 10:02 PM
You are going about it the wrong way.

What mail component are you using?

What OS do you have?

If you are using cdosys, then use:
MyMail.AddAttachment "c:\path\image.gif or whatever"

for cdonts, use:

oMail.Attachfile ="C:\path\image.gif or whatever.

ric73
10-16-2006, 12:10 PM
Thank You. here is the complete code I am using. Below is the file that contains the form with the attribute ENCTYPE:


<!--#include file="emailACC.asp"-->
<%

If Request.Form.Count > 0 Then

'Form submission
SendContactEmail()
SendResponseEmail()

End If

Sub SendContactEmail()
Dim strFrom
Dim strTo
Dim strSubject
Dim strBody
Dim strAttachF

strFrom = Request.Form("Name") & " <" & ValidateFrom(Request.Form("EMail")) & ">"
strTo = "ricardo@redcube.org"
strSubject = "Contact"
strBody = _
"Name: " & Request.Form("Name") & vbCrLf & _
"Telephone: " & Request.Form("Telephone") & vbCrLf & _
"EMail: " & Request.Form("EMail") & vbCrLf & _
"Architect: " & Request.Form("Architect") & vbCrLf & _
"Year Built: " & Request.Form("Year") & vbCrLf & _
"Location: " & Request.Form("Location") & vbCrLf & _
"Country: " & Request.Form("Country") & vbCrLf & _
"File: " & Request.Form("filefield") & vbCrLf & _
"Comments: " & Request.Form("Comments") & vbCrLf
strAttachF = Request.Form("filefield")
EmailText strFrom, strTo, "", strSubject, strBody, strAttachF
End Sub


Sub SendResponseEmail()
Dim strFrom
Dim strTo
Dim strSubject
Dim strBody


strFrom = "Ricardo B <ricardo@redcube.org>"
strTo = Request.Form("Name") & " <" & ValidateFrom(Request.Form("EMail")) & ">"
strSubject = "Your message to Douglas Newby has been sent"
strBody = _
"Dear Architecture Aficionado," & vbCrLf & vbCrLf & _
"Thank you for your interest in architecture, neighborhoods and good design. We value you and your efforts and hope we will be able to participate in your pursuits." & vbCrLf & vbCrLf & _
"Sincerely," & vbCrLf & vbCrLf & _
"Douglas Newby" & vbCrLf & vbCrLf & vbCrLf & _
"Your message:" & vbCrLf & _
Request.Form("Comments")
EmailText strFrom, strTo, "", strSubject, strBody
End Sub


%>
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber1" height="86">
<tr>
<td width="50%" height="86">
<DIV class="ACCText" style="width: 300; height: 380">
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber2">
<tr>
<td width="60%">
<DIV class="ACCText">You can now submit your favourite property to the
Architecture Coast to Coast site. Let us know your details along with
your favourite property details and we will feature it in our site.
<p>Most award-winning architects have designed an <b>architecturally significant</b>
project in the city in which they live. Often the finest architects will design architecturally
significant properties outside of their city or region, designing important properties across the country,
pollinating their style, design and architectural point of view whether it is in other cities, or in the
mountains, on the coast, on beaches, around lakes, in the plains or remote areas of splendid beauty.</p>
<p>If you are aware of an Architecturally Significant home and would
like to see it featured please don not hesitate to contact us using
the form to your right.</p>
</td>
</tr>
</table>
</td>
<td width="50%" height="86">

<FORM method="post" class="ContactField" ENCTYPE="multipart/form-data">

<DIV class="ContactLabelACC">Name:</DIV>
<DIV><INPUT type="text" name="Name" class="ContactFieldACC" size="50"></DIV>
<br>
<DIV class="ContactLabelACC">Telephone:</DIV>
<DIV><INPUT type="text" name="Telephone" class="ContactFieldACC" size="20"></DIV>
<br>
<DIV class="ContactLabelACC">EMail:</DIV>
<DIV><INPUT type="text" name="EMail" class="ContactFieldACC" size="50"></DIV>
<br>
<DIV class="ContactLabelACC">Architect:</DIV>
<DIV><INPUT type="text" name="Architect" class="ContactFieldACC" size="50"></DIV>
<br>
<DIV class="ContactLabelACC">Year Built:</DIV>
<DIV><INPUT type="text" name="Year" class="ContactFieldACC" size="20"></DIV>
<br>
<DIV class="ContactLabelACC">Location:</DIV>
<DIV><INPUT type="text" name="Location" class="ContactFieldACC" size="50"></DIV>
<br>
<DIV class="ContactLabelACC">Country:</DIV>
<DIV><INPUT type="text" name="Country" class="ContactFieldACC" size="50"></DIV>
<br>
<DIV class="ContactLabelACC">Upload Image:</DIV>
<DIV><input type="file" name="filefield" class="ContactFieldACC" size="50"></DIV>
<br>
<DIV class="ContactLabelACC">Comments:</DIV>
<DIV><TEXTAREA name="Comments" class="ContactFieldACC" scroll="auto" rows="1" cols="50"></TEXTAREA></DIV>

<DIV class="ContactSubmit"><INPUT type="image" src="/images/submit-acc.gif" width="87" height="17" align="middle"></DIV>
<DIV class="ContactNote">NOTE: Your information will never be <br> shared with a third party!</DIV>
</FORM>


</td>
</tr>
</table>


and here is the emailACC.asp where all the email handling code is:


<%

Sub SendEmail(strFrom, strTo, strBcc, strSubject, strBody, strAttachF, intBodyFormat)
Dim cdoMsg
Dim cdoConfig
Set cdoMsg = Server.CreateObject("CDO.Message")
Set cdoConfig = Server.CreateObject("CDO.Configuration")

With cdoConfig.Fields
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 1 '1=local, 2=remote, 3=exchange
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "http://127.0.0.1"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverpickupdirectory") = "C:\inetpub\mailroot\pickup"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
.Update
End With

Set cdoMsg.Configuration = cdoConfig
cdoMsg.To = strTo
'cdoMsg.Cc = strCc
cdoMsg.Bcc = strBcc
cdoMsg.From = strFrom
cdoMsg.Subject = strSubject
cdoMsg.TextBody = strBody
cdoMsg.Fields("urn:schemas:httpmail:importance").Value = 1
cdoMsg.Fields.Update
cdoMsg.AddAttachment = strAttachF
cdoMsg.Send
Set cdoMsg = Nothing
Set cdoConfig = Nothing

End Sub


Sub EmailText(strFrom, strTo, strBcc, strSubject, strBody, strAttachF)
Dim intBodyFormat

intBodyFormat = 1

SendEmail strFrom, strTo, strBcc, strSubject, strBody, strAttachF, intBodyFormat
End Sub


Sub EmailHtml(strFrom, strTo, strBcc, strSubject, strBody)
Dim intBodyFormat

intBodyFormat = 0

SendEmail strFrom, strTo, strBcc, strSubject, strBody, intBodyFormat
End Sub


'Functions
'---------
Function ValidateFrom(strFrom)
Dim regEx
Dim intRetVal
Set regEx = New RegExp
regEx.Pattern = ".*@.*\..*"
intRetVal = regEx.Test(strFrom)

If Not intRetVal Then
ValidateFrom = strFrom & " <invalid-address@" & Request.ServerVariables("REMOTE_ADDR") & ">"
Else
ValidateFrom = strFrom
End If

Set regEx = Nothing
End Function

%>


If I don't use ENCTYPE on the form I get a error and if I use it then nothing happens (i don't receive any email). I think I am now passing all the right values but that my server does not support this VBscript??

Thank you for any help. Regards

simflex
10-27-2006, 08:27 PM
sorry, your email went to my junk mail folder.

I normally just empty junk mail folder but for some reason I decided to open it. good a thing I did.

Any way, I said in my last response that the type of form email you are setting up won't work with enctype="multipart/form-data.

You use this for either uploading to a server to the database as far as I know.

If you are trying to send an email with an attachment, use

cdoMsg.AddAttachment = strAttachF

be sure to define strAttachF somewhere.