Martin Cotterill
asked on
Upload an image on a form and email it
Hi Experts All
I am creating a website (voluntarily) for a children's cancer charity. On the site we will have a form that visitors complete with their family stories. When they have completed the form, they click the submit button and the story is sent to us as an email.
Some stories have pictures and I would like to provide a way of allowing the user to upload an image from their computer whch is then sent with the form.
I have found Pure ASP File Upload at http://www.asp101.com/articles/jacob/scriptupload.asp and it seems that it might be the easiest way to upload an image, but the two examples it gives for saving are to disk or database.
How would I use the script to email the image and the contents of the form at the same time?
From reading other questions here at EE it seems that this needs to be done in two parts; upload then email. Is this correct and if so, what is the easiest way to do it?
I've also seen somewhere that you should use CDO not CDONTS because there are problems with CDONTS and has been deprecated, is this correct? The reason I mention this is that the example I saw there made no mention of how you would use this with a form.
I'm sorry if this is basic stuff but I'm relatively new to ASP and this is the first form I've done.
Regards
Pantyboy
I am creating a website (voluntarily) for a children's cancer charity. On the site we will have a form that visitors complete with their family stories. When they have completed the form, they click the submit button and the story is sent to us as an email.
Some stories have pictures and I would like to provide a way of allowing the user to upload an image from their computer whch is then sent with the form.
I have found Pure ASP File Upload at http://www.asp101.com/articles/jacob/scriptupload.asp and it seems that it might be the easiest way to upload an image, but the two examples it gives for saving are to disk or database.
How would I use the script to email the image and the contents of the form at the same time?
From reading other questions here at EE it seems that this needs to be done in two parts; upload then email. Is this correct and if so, what is the easiest way to do it?
I've also seen somewhere that you should use CDO not CDONTS because there are problems with CDONTS and has been deprecated, is this correct? The reason I mention this is that the example I saw there made no mention of how you would use this with a form.
I'm sorry if this is basic stuff but I'm relatively new to ASP and this is the first form I've done.
Regards
Pantyboy
ASKER
Hi Stilgar
Thanks for the reply and the update on CDO.
How would I keep the file in a memory buffer? As I said, the only examples I've seen are saving to disk or database.
If I have to save the file to disk for ease of use, how would I delete it after the email has been sent?
Regards
Martin
Thanks for the reply and the update on CDO.
How would I keep the file in a memory buffer? As I said, the only examples I've seen are saving to disk or database.
If I have to save the file to disk for ease of use, how would I delete it after the email has been sent?
Regards
Martin
I'm not familiar with Pure ASP upload, so I can't answer you on the memory buffer question. I have used with another free, pure ASP, component in the past which allowed it.
Using FSO you can delete the file after use - http://www.w3schools.com/asp/met_deletefile.asp.
Stilgar.
Using FSO you can delete the file after use - http://www.w3schools.com/asp/met_deletefile.asp.
Stilgar.
CDOSYS is supported by Server 2003. It is CDONTS that has been discontinued.
Pure ASP looks like it has the capability to email an attachment: http://www.motobit.com/help/scptutl/pure-asp-upload.htm
Though, you will have to update the code to use CDOSYS.
Pure ASP looks like it has the capability to email an attachment: http://www.motobit.com/help/scptutl/pure-asp-upload.htm
Though, you will have to update the code to use CDOSYS.
Sorry, I meant to give you this link to the email code: http://www.motobit.com/help/scptutl/sa271.htm
ASKER
Hi fuzzboxer
Thanks for the links.
I'll give them a play and get back to you soonest but looking good so far.
Regards
Pantyboy
Thanks for the links.
I'll give them a play and get back to you soonest but looking good so far.
Regards
Pantyboy
ASKER
Hi again fuzzboxer
I'm sorry that it took so much time to get back to you but we had a small domestic situation here 'Chez Pantyboy'. My girlfriend slipped on some steps and ended up with a broken arm. Hey Ho.
Any road up. I can't get the script to work. I've tried all manner of ways but I'm doing something wrong.
If I use their example form it works fine, if I use my form... nothing. I get errors.
If I post my code would you be able to help me out and correct my mistakes?
Warm regards
Martin
I'm sorry that it took so much time to get back to you but we had a small domestic situation here 'Chez Pantyboy'. My girlfriend slipped on some steps and ended up with a broken arm. Hey Ho.
Any road up. I can't get the script to work. I've tried all manner of ways but I'm doing something wrong.
If I use their example form it works fine, if I use my form... nothing. I get errors.
If I post my code would you be able to help me out and correct my mistakes?
Warm regards
Martin
Post your code and I'll check it out.
ASKER
Hi fuzzbox
I'm fed up now. I've tried all sorts and still can't figure it out. With a bit of luck your fresh eyes will spot the problem within minutes if not seconds.
Here's my page code:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!--#include file="Connections/CCC.asp" -->
<%
Dim TemplateFooter
Dim TemplateFooter_cmd
Dim TemplateFooter_numRows
Set TemplateFooter_cmd = Server.CreateObject ("ADODB.Command")
TemplateFooter_cmd.ActiveC onnection = MM_CCC_STRING
TemplateFooter_cmd.Command Text = "SELECT * FROM qryCharityContactDetails"
TemplateFooter_cmd.Prepare d = true
Set TemplateFooter = TemplateFooter_cmd.Execute
TemplateFooter_numRows = 0
%>
<%
Dim Headers
Dim Headers_cmd
Dim Headers_numRows
Set Headers_cmd = Server.CreateObject ("ADODB.Command")
Headers_cmd.ActiveConnecti on = MM_CCC_STRING
Headers_cmd.CommandText = "SELECT * FROM tblMainSections WHERE ID = 3"
Headers_cmd.Prepared = true
Set Headers = Headers_cmd.Execute
Headers_numRows = 0
%>
<%
'Sample file Form-Email.asp
' Let's you send one an email with one or more attachments.
'Global declarations.
'Get temporary folder
Dim ResultHTML
'Create upload form
'Using Huge-ASP file upload
'Dim Form: Set Form = Server.CreateObject("Scrip tUtils.ASP Form")
'Using Pure-ASP file upload
Dim Form: Set Form = New ASPForm %><!--#INCLUDE FILE="_upload.asp"--><%
Server.ScriptTimeout = 1000
'Do not upload data greater than 10MB.
Form.SizeLimit = &HA00000
'Progress bar window will receive the same ID.
Form.UploadID = Request.QueryString("Uploa dID")'{/b}
Const fsCompletted = 0
If Form.State = fsCompletted Then 'Completted
ResultHTML = ProcessForm
ElseIf Form.State > 10 then
Const fsSizeLimit = &HD
Select case Form.State
case fsSizeLimit: ResultHTML = "<br><Font Color=red>Source form size (" & Form.TotalBytes & "B) exceeds form limit (" & Form.SizeLimit & "B)</Font><br>"
case else ResultHTML = "<br><Font Color=red>Some form error.</Font><br>"
end Select
End If
if request.QueryString("Actio n") = "Cancel" then
ResultHTML = "<br><b>Upload was cancelled</b>"
end if
Function TempFolder()
Dim FS
Set FS = CreateObject("Scripting.Fi leSystemOb ject")
'Get temporary folder
TempFolder = FS.GetSpecialFolder(2) & "\emailtemp"
End Function
Sub DeleteFile(FileName)
Dim FS
Set FS = CreateObject("Scripting.Fi leSystemOb ject")
FS.DeleteFile FileName
End Sub
Function ProcessForm
Dim eName, eAddress, ePostcode, ePhone, eMail, eStory
'get source form fields - From, To, Subject and Message
eName = Form("Name")
eAddress = Form("Address")
ePostcode = Form("PostCode")
ePhone = Form("PhoneNumber")
eMail = Form("EmailAddress")
eStory = Form("Story")
Dim HTML
HTML = "<br><Font Color=red> Server-side ASP script accepted source form with fields and files and email object was created. "
HTML = HTML & "<br>From: <b>" & eName & "</b>"
HTML = HTML & "<br>Address: <b>" & eAddress & "</b>"
HTML = HTML & "<br>Postcode: <b>" & ePostcode & "</b>"
HTML = HTML & "<br>Phone: <b>" & ePhone & "</b>"
HTML = HTML & "<br>Email: <b>" & eMail & "</b>"
HTML = HTML & "<br>Story: <b>" & eStory & "</b>"
Dim objNewMail, File, FileName
'Create a new email message
Set objNewMail = CreateObject("CDONTS.NewMa il")
Const CdoMailFormatMime = 0
objNewMail.MailFormat = CdoMailFormatMime
objNewMail.To = "name@domain.com"
objNewMail.Subject = "From the Website"
'Save source files to temporary folder
'Add these files to the new e-mail
HTML = HTML & "<br>Attachments:"
For Each File In Form.Files.Items
'If source file is specified.
If Len(File.FileName) > 0 Then
HTML = HTML & "<br> " & File.Name & ": <b>" & File.FileName & ", " & File.Length \ 1024 & "kB</b>"
FileName = TempFolder & "\" & File.FileName
File.SaveAs FileName
objNewMail.AttachFile FileName
End If
Next
'Send the new email
objNewMail.Send eName, eAddress, ePostcode, ePhone, eMail, eStory
'delete temporary files
For Each File In Form.Files.Items
If Len(File.FileName) > 0 Then
FileName = TempFolder & "\" & File.FileName
on error resume next
DeleteFile FileName
End If
Next
HTML = HTML & "</Font><br>"
ProcessForm = HTML
End Function
'{b}get an unique upload ID for this upload script and progress bar.
Dim UploadID, PostURL
UploadID = Form.NewUploadID
'Send this ID as a UploadID QueryString parameter to this script.
PostURL = Request.ServerVariables("S CRIPT_NAME ") & "?UploadID=" & UploadID'{/b}
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/mainT emplate.dw t.asp" codeOutsideHTMLIsLocked="f alse" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="keywords" content="childhood cancer, childrens cancer, children's cancer, child cancer, family support, cancer care, christian lewis trust, childrens cancer charity, bereavement support, family breaks, play therapy">
<meta name="description" content="The Christian Lewis Trust provides ongoing care and support for children with cancer and their families. Our site provides you with information about us and what we do and how you can help us to help children with cancer." />
<!-- InstanceBeginEditable name="doctitle" -->
<title>Christian Lewis Trust Children's Cancer Charity - Supporting and Caring for Children with Cancer and Their Families - Send Us Your Story</title>
<!-- InstanceEndEditable -->
<link href="Scripts/ChristianLew isTrust.cs s" rel="stylesheet" type="text/css" media="screen"></link>
<link rel="shortcut icon" href="favicon.ico"></link>
<script language="javascript" type="text/javascript" src="Scripts/ChristianLewi sTrust.js" ></script>
<!-- InstanceBeginEditable name="head" --><!-- InstanceEndEditable -->
</head>
<body>
<table border="0" align="center" cellpadding="10" cellspacing="10" id="pageBody">
<tr>
<td width="200" height="80" id="leftColContent" style="background-image:ur l(system/l ogoBackgro und.gif)"> </td >
<td width="490" height="80" align="center" style="background-image:ur l(system/l ogoBackgro und.gif)"> <img src="system/ChristianLewis TrustLogoF ull.gif" alt="Logo of Christian Lewis Trust Childrens Cancer Charity" width="297" height="80" align="right"></td>
</tr>
<tr valign="middle">
<td width="200" align="center" class="leftColHeading" id="leftColContent" style="background-image:ur l(system/m enuBackgro und.gif)"> <!-- InstanceBeginEditable name="leftColumnHeading" --><%=(Headers.Fields.Item ("Section" ).Value)%> <!-- InstanceEndEditable --></td>
<td width="490" class="NavBarSeperator" style="background-image:ur l(system/m enuBackgro und.gif)"> <a href="default.asp" class="NavBar">Home</a> | <a href="FamilyServices.asp" class="NavBar">Family Services</a> | <a href="DonationsAndFundrais ing.asp" class="NavBar">Donations and Fundraising</a> | <a href="NewsAndStories.asp" class="NavBar">Trust News and Stories</a></td>
</tr>
<tr>
<td width="200" valign="top" class="leftColContent" id="contentBorder"><!-- InstanceBeginEditable name="leftColumnContent" -->
<!--#include file="NewsAndStoriesMenu.a sp" -->
<!-- InstanceEndEditable --></td>
<td width="490" valign="top" id="contentBorder"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="Heading" id="Heading"><!-- InstanceBeginEditable name="pageHeading" -->Send us your own story<!-- InstanceEndEditable --></td>
</tr>
<tr>
<td><!-- InstanceBeginEditable name="pageImage" --><img src="system/blank.gif" width="490" height="1" /><!-- InstanceEndEditable --></td>
</tr>
<tr>
<td class="tdContent"><!-- InstanceBeginEditable name="pageContent" -->
<!--<form id="StoryForm" name="StoryForm" method="post" action="MessageAndStoryCon firm.asp?s tory=Famil y%20Story" >-->
<form method="post" ENCTYPE="multipart/form-da ta" OnSubmit="return ProgressBar();" Action="<%=PostURL%>">
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="5">
<tr>
<td width="100" align="left" nowrap="nowrap">Full Name:</td>
<td align="left" width="100%"><input name="Name" type="text" class="inputBox" value="<%=Form("Name")%>" /></td>
</tr>
<tr>
<td align="left" valign="top">Full Address:</td>
<td align="left"><textarea name="Address" rows="5" class="inputBox" value="<%=Form("Address")% >"></texta rea></td>
</tr>
<tr>
<td align="left">Postcode:</td >
<td align="left"><input name="PostCode" type="text" class="inputBox" value="<%=Form("PostCode") %>" /></td>
</tr>
<tr>
<td align="left">Phone Number:</td>
<td align="left"><input name="PhoneNumber" type="text" class="inputBox" value="<%=Form("PhoneNumbe r")%>" /></td>
</tr>
<tr>
<td align="left">Email Address:</td>
<td align="left"><input name="EmailAddress" type="text" class="inputBox" value="<%=Form("EmailAddre ss")%>" /></td>
</tr>
<tr>
<td colspan="2">Your Story:</td>
</tr>
<tr>
<td colspan="2"><textarea name="Story" rows="10" class="inputBox" value="<%=Form("Story")%>" ></textare a></td>
</tr>
<tr>
<td colspan="2">Add a photo to illustrate your story:
<!--Form size limit is <%=Form.SizeLimit%>B (<%=Form.SizeLimit \ 1024 %>kB).<br>-->
<DIV ID=files>
<input type="file" name="Photo" class="inputBox">
</DIV>
<!--<INPUT Type=button Value="Add a file" OnClick=return(Expand())
Style="BORDER-RIGHT: 0px; BORDER-TOP: 0px; BACKGROUND: yellow; BORDER-LEFT: 0px; CURSOR: hand; BORDER-BOTTOM: 0px">-->
</td></tr>
<tr>
<td colspan="2">
<table width="100%">
<tr>
<td width="50%" align="right" style="padding-right:10px" ><input type="submit" name="Submit" value="Submit" /></td>
<td width="50%" align="left" style="padding-left:10px"> <input type="reset" name="Reset" value="Reset" /></td>
</tr>
</table>
</td>
</tr>
</table>
</form>
<p>
<%=ResultHTML%>
<SCRIPT>
//Script to add an attachment file field
var nfiles = 1;
function Expand(){
nfiles++
var adh = '<BR> Attachment '+nfiles+' : <input type="file" name="File '+nfiles+'">';
files.insertAdjacentHTML(' BeforeEnd' ,adh);
return false;
};
//Open a window with progress bar indicator.
function ProgressBar(){
var ProgressURL
ProgressURL = 'progress.asp?UploadID=<%= UploadID%> '
var v = window.open(ProgressURL,'_ blank','to olbar=no,l ocation=no ,directori es=no,stat us=no,menu bar=no,scr ollbars=no ,resizable =yes,width =350,heigh t=200')
return true;
}
</SCRIPT>
<!-- InstanceEndEditable --></td>
</tr>
</table></td>
</tr>
<tr>
<td width="200" id="leftColContent" style="border:#2B3D8F thin solid"> </td>
<td width="490" align="center" class="footer" style="border:#2B3D8F thin solid"><a href="DonationsAndFundrais ing.asp" class="footerLink">Home</a > | <a href="FamilyServices.asp" class="footerLink">Family Services</a> | <a href="DonationsAndFundrais ing.asp" class="footerLink">Donatio ns And Fundraising</a> | <a href="NewsAndStories.asp" class="footerLink">Trust News and Stories</a> | <a href="AboutUs.asp" class="footerLink">About Us</a> | <a href="ContactUs.asp" class="footerLink">Contact Us</a></td>
</tr>
<tr>
<td colspan="2" align="center" valign="top" class="footer"><%=(Templat eFooter.Fi elds.Item( "CharityNa me").Value )%>, <%=(TemplateFooter.Fields. Item("Addr ess").Valu e)%> - Tel: <%=(TemplateFooter.Fields. Item("Tele phoneNumbe r").Value) %> - Fax: <%=(TemplateFooter.Fields. Item("FaxN umber").Va lue)%><br />
Charity Registration Number: <%=(TemplateFooter.Fields. Item("Char ityNumber" ).Value)%> - © <%=(TemplateFooter.Fields. Item("Char ityName"). Value)%>
<br />
<span class="smallerFont"><b><%= (TemplateF ooter.Fiel ds.Item("C harityName ").Value)% > is entirely dependent on voluntary donations</b></span></td>
</tr>
</table>
</body>
<!-- InstanceEnd --></html>
<%
TemplateFooter.Close()
Set TemplateFooter = Nothing
%>
<%
Headers.Close()
Set Headers = Nothing
%>
----------
This is the error I'm getting:
Microsoft VBScript runtime error '800a01c2'
Wrong number of arguments or invalid property assignment: 'objNewMail.sEnd'
/StoryForm.asp, line 125
--------
Line 125 = objNewMail.Send eName, eAddress, ePostcode, ePhone, eMail, eStory
--------
Warm regards
Martin
I'm fed up now. I've tried all sorts and still can't figure it out. With a bit of luck your fresh eyes will spot the problem within minutes if not seconds.
Here's my page code:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!--#include file="Connections/CCC.asp"
<%
Dim TemplateFooter
Dim TemplateFooter_cmd
Dim TemplateFooter_numRows
Set TemplateFooter_cmd = Server.CreateObject ("ADODB.Command")
TemplateFooter_cmd.ActiveC
TemplateFooter_cmd.Command
TemplateFooter_cmd.Prepare
Set TemplateFooter = TemplateFooter_cmd.Execute
TemplateFooter_numRows = 0
%>
<%
Dim Headers
Dim Headers_cmd
Dim Headers_numRows
Set Headers_cmd = Server.CreateObject ("ADODB.Command")
Headers_cmd.ActiveConnecti
Headers_cmd.CommandText = "SELECT * FROM tblMainSections WHERE ID = 3"
Headers_cmd.Prepared = true
Set Headers = Headers_cmd.Execute
Headers_numRows = 0
%>
<%
'Sample file Form-Email.asp
' Let's you send one an email with one or more attachments.
'Global declarations.
'Get temporary folder
Dim ResultHTML
'Create upload form
'Using Huge-ASP file upload
'Dim Form: Set Form = Server.CreateObject("Scrip
'Using Pure-ASP file upload
Dim Form: Set Form = New ASPForm %><!--#INCLUDE FILE="_upload.asp"--><%
Server.ScriptTimeout = 1000
'Do not upload data greater than 10MB.
Form.SizeLimit = &HA00000
'Progress bar window will receive the same ID.
Form.UploadID = Request.QueryString("Uploa
Const fsCompletted = 0
If Form.State = fsCompletted Then 'Completted
ResultHTML = ProcessForm
ElseIf Form.State > 10 then
Const fsSizeLimit = &HD
Select case Form.State
case fsSizeLimit: ResultHTML = "<br><Font Color=red>Source form size (" & Form.TotalBytes & "B) exceeds form limit (" & Form.SizeLimit & "B)</Font><br>"
case else ResultHTML = "<br><Font Color=red>Some form error.</Font><br>"
end Select
End If
if request.QueryString("Actio
ResultHTML = "<br><b>Upload was cancelled</b>"
end if
Function TempFolder()
Dim FS
Set FS = CreateObject("Scripting.Fi
'Get temporary folder
TempFolder = FS.GetSpecialFolder(2) & "\emailtemp"
End Function
Sub DeleteFile(FileName)
Dim FS
Set FS = CreateObject("Scripting.Fi
FS.DeleteFile FileName
End Sub
Function ProcessForm
Dim eName, eAddress, ePostcode, ePhone, eMail, eStory
'get source form fields - From, To, Subject and Message
eName = Form("Name")
eAddress = Form("Address")
ePostcode = Form("PostCode")
ePhone = Form("PhoneNumber")
eMail = Form("EmailAddress")
eStory = Form("Story")
Dim HTML
HTML = "<br><Font Color=red> Server-side
HTML = HTML & "<br>From: <b>" & eName & "</b>"
HTML = HTML & "<br>Address: <b>" & eAddress & "</b>"
HTML = HTML & "<br>Postcode: <b>" & ePostcode & "</b>"
HTML = HTML & "<br>Phone: <b>" & ePhone & "</b>"
HTML = HTML & "<br>Email: <b>" & eMail & "</b>"
HTML = HTML & "<br>Story: <b>" & eStory & "</b>"
Dim objNewMail, File, FileName
'Create a new email message
Set objNewMail = CreateObject("CDONTS.NewMa
Const CdoMailFormatMime = 0
objNewMail.MailFormat = CdoMailFormatMime
objNewMail.To = "name@domain.com"
objNewMail.Subject = "From the Website"
'Save source files to temporary folder
'Add these files to the new e-mail
HTML = HTML & "<br>Attachments:"
For Each File In Form.Files.Items
'If source file is specified.
If Len(File.FileName) > 0 Then
HTML = HTML & "<br> " & File.Name & ": <b>" & File.FileName & ", " & File.Length \ 1024 & "kB</b>"
FileName = TempFolder & "\" & File.FileName
File.SaveAs FileName
objNewMail.AttachFile FileName
End If
Next
'Send the new email
objNewMail.Send eName, eAddress, ePostcode, ePhone, eMail, eStory
'delete temporary files
For Each File In Form.Files.Items
If Len(File.FileName) > 0 Then
FileName = TempFolder & "\" & File.FileName
on error resume next
DeleteFile FileName
End If
Next
HTML = HTML & "</Font><br>"
ProcessForm = HTML
End Function
'{b}get an unique upload ID for this upload script and progress bar.
Dim UploadID, PostURL
UploadID = Form.NewUploadID
'Send this ID as a UploadID QueryString parameter to this script.
PostURL = Request.ServerVariables("S
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/mainT
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="keywords" content="childhood cancer, childrens cancer, children's cancer, child cancer, family support, cancer care, christian lewis trust, childrens cancer charity, bereavement support, family breaks, play therapy">
<meta name="description" content="The Christian Lewis Trust provides ongoing care and support for children with cancer and their families. Our site provides you with information about us and what we do and how you can help us to help children with cancer." />
<!-- InstanceBeginEditable name="doctitle" -->
<title>Christian Lewis Trust Children's Cancer Charity - Supporting and Caring for Children with Cancer and Their Families - Send Us Your Story</title>
<!-- InstanceEndEditable -->
<link href="Scripts/ChristianLew
<link rel="shortcut icon" href="favicon.ico"></link>
<script language="javascript" type="text/javascript" src="Scripts/ChristianLewi
<!-- InstanceBeginEditable name="head" --><!-- InstanceEndEditable -->
</head>
<body>
<table border="0" align="center" cellpadding="10" cellspacing="10" id="pageBody">
<tr>
<td width="200" height="80" id="leftColContent" style="background-image:ur
<td width="490" height="80" align="center" style="background-image:ur
</tr>
<tr valign="middle">
<td width="200" align="center" class="leftColHeading" id="leftColContent" style="background-image:ur
<td width="490" class="NavBarSeperator" style="background-image:ur
</tr>
<tr>
<td width="200" valign="top" class="leftColContent" id="contentBorder"><!-- InstanceBeginEditable name="leftColumnContent" -->
<!--#include file="NewsAndStoriesMenu.a
<!-- InstanceEndEditable --></td>
<td width="490" valign="top" id="contentBorder"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="Heading" id="Heading"><!-- InstanceBeginEditable name="pageHeading" -->Send us your own story<!-- InstanceEndEditable --></td>
</tr>
<tr>
<td><!-- InstanceBeginEditable name="pageImage" --><img src="system/blank.gif" width="490" height="1" /><!-- InstanceEndEditable --></td>
</tr>
<tr>
<td class="tdContent"><!-- InstanceBeginEditable name="pageContent" -->
<!--<form id="StoryForm" name="StoryForm" method="post" action="MessageAndStoryCon
<form method="post" ENCTYPE="multipart/form-da
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="5">
<tr>
<td width="100" align="left" nowrap="nowrap">Full Name:</td>
<td align="left" width="100%"><input name="Name" type="text" class="inputBox" value="<%=Form("Name")%>" /></td>
</tr>
<tr>
<td align="left" valign="top">Full Address:</td>
<td align="left"><textarea name="Address" rows="5" class="inputBox" value="<%=Form("Address")%
</tr>
<tr>
<td align="left">Postcode:</td
<td align="left"><input name="PostCode" type="text" class="inputBox" value="<%=Form("PostCode")
</tr>
<tr>
<td align="left">Phone Number:</td>
<td align="left"><input name="PhoneNumber" type="text" class="inputBox" value="<%=Form("PhoneNumbe
</tr>
<tr>
<td align="left">Email Address:</td>
<td align="left"><input name="EmailAddress" type="text" class="inputBox" value="<%=Form("EmailAddre
</tr>
<tr>
<td colspan="2">Your Story:</td>
</tr>
<tr>
<td colspan="2"><textarea name="Story" rows="10" class="inputBox" value="<%=Form("Story")%>"
</tr>
<tr>
<td colspan="2">Add a photo to illustrate your story:
<!--Form size limit is <%=Form.SizeLimit%>B (<%=Form.SizeLimit \ 1024 %>kB).<br>-->
<DIV ID=files>
<input type="file" name="Photo" class="inputBox">
</DIV>
<!--<INPUT Type=button Value="Add a file" OnClick=return(Expand())
Style="BORDER-RIGHT: 0px; BORDER-TOP: 0px; BACKGROUND: yellow; BORDER-LEFT: 0px; CURSOR: hand; BORDER-BOTTOM: 0px">-->
</td></tr>
<tr>
<td colspan="2">
<table width="100%">
<tr>
<td width="50%" align="right" style="padding-right:10px"
<td width="50%" align="left" style="padding-left:10px">
</tr>
</table>
</td>
</tr>
</table>
</form>
<p>
<%=ResultHTML%>
<SCRIPT>
//Script to add an attachment file field
var nfiles = 1;
function Expand(){
nfiles++
var adh = '<BR> Attachment '+nfiles+' : <input type="file" name="File '+nfiles+'">';
files.insertAdjacentHTML('
return false;
};
//Open a window with progress bar indicator.
function ProgressBar(){
var ProgressURL
ProgressURL = 'progress.asp?UploadID=<%=
var v = window.open(ProgressURL,'_
return true;
}
</SCRIPT>
<!-- InstanceEndEditable --></td>
</tr>
</table></td>
</tr>
<tr>
<td width="200" id="leftColContent" style="border:#2B3D8F thin solid"> </td>
<td width="490" align="center" class="footer" style="border:#2B3D8F thin solid"><a href="DonationsAndFundrais
</tr>
<tr>
<td colspan="2" align="center" valign="top" class="footer"><%=(Templat
Charity Registration Number: <%=(TemplateFooter.Fields.
<br />
<span class="smallerFont"><b><%=
</tr>
</table>
</body>
<!-- InstanceEnd --></html>
<%
TemplateFooter.Close()
Set TemplateFooter = Nothing
%>
<%
Headers.Close()
Set Headers = Nothing
%>
----------
This is the error I'm getting:
Microsoft VBScript runtime error '800a01c2'
Wrong number of arguments or invalid property assignment: 'objNewMail.sEnd'
/StoryForm.asp, line 125
--------
Line 125 = objNewMail.Send eName, eAddress, ePostcode, ePhone, eMail, eStory
--------
Warm regards
Martin
Replace that line with this:
objNewMail.Htmlbody = HTML
objNewMail.Send
objNewMail.Htmlbody = HTML
objNewMail.Send
ASKER
Hi F
Thanks for the reply.
I now get the error:
Microsoft VBScript runtime error '800a01b6'
Object doesn't support this property or method: 'objNewMail.Htmlbody'
/StoryForm.asp, line 126
Line 126 = objNewMail.Htmlbody
If I change it to:
objNewMail.Send HTML
I get this error
Microsoft VBScript runtime error '800a0005'
Invalid procedure call or argument
/StoryForm.asp, line 127
Line 127 = objNewMail.Send HTML
This change:
objNewMail.Htmlbody = HTML
objNewMail.Send HTML
Gets this error:
Microsoft VBScript runtime error '800a01b6'
Object doesn't support this property or method: 'objNewMail.Htmlbody'
/StoryForm.asp, line 126
Line 126 = objNewMail.Htmlbody = HTML
and if I just use 'objNewMail.Send' I get no errors but I don't get an email either.
Just for the record, if I reduce the number of fields on the 'objNewMail.Send...' line I don't get any errors, but no email is sent. Also, when the 'Submit' button is clicked the 'Full Address', 'Your Story' and the attachment sections are cleared, but the rest are still visible.
Also, according to Dreamweaver the 'value' attribute is not supported in the <textarea> tag in a whole bunch of browsers.
Could these have any effect?
Regards
Martin
Thanks for the reply.
I now get the error:
Microsoft VBScript runtime error '800a01b6'
Object doesn't support this property or method: 'objNewMail.Htmlbody'
/StoryForm.asp, line 126
Line 126 = objNewMail.Htmlbody
If I change it to:
objNewMail.Send HTML
I get this error
Microsoft VBScript runtime error '800a0005'
Invalid procedure call or argument
/StoryForm.asp, line 127
Line 127 = objNewMail.Send HTML
This change:
objNewMail.Htmlbody = HTML
objNewMail.Send HTML
Gets this error:
Microsoft VBScript runtime error '800a01b6'
Object doesn't support this property or method: 'objNewMail.Htmlbody'
/StoryForm.asp, line 126
Line 126 = objNewMail.Htmlbody = HTML
and if I just use 'objNewMail.Send' I get no errors but I don't get an email either.
Just for the record, if I reduce the number of fields on the 'objNewMail.Send...' line I don't get any errors, but no email is sent. Also, when the 'Submit' button is clicked the 'Full Address', 'Your Story' and the attachment sections are cleared, but the rest are still visible.
Also, according to Dreamweaver the 'value' attribute is not supported in the <textarea> tag in a whole bunch of browsers.
Could these have any effect?
Regards
Martin
Sorry, I should have made it objNewMail.Body = HTML since you are using CDONTS.
ASKER
Hi Fuzz
OK, that cured the errors but it still seems that it's not acually sending anything.
I've put the line 'objNewMail.To = "name@domain.com"' (I've changed this to my real email address) into the code based on what I've read but I'm not sure if this is right. I've also added the 'objNewMail.Subject = ...'.
Regards
Martin
OK, that cured the errors but it still seems that it's not acually sending anything.
I've put the line 'objNewMail.To = "name@domain.com"' (I've changed this to my real email address) into the code based on what I've read but I'm not sure if this is right. I've also added the 'objNewMail.Subject = ...'.
Regards
Martin
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi Fuzzboxer
Thanks for the new code.
I came across one problem that was easy to solve which was the line 'objNewMail.AttachFile FileName' which should have been 'objNewMail.AddAttachment FileName'.
The other problem an error message that says:
CDO.Message.1 error '8004020d'
At least one of the From or Sender fields is required, and neither was found.
/StoryForm.asp, line 124
The line is: 'objNewMail.Send'
With a bit of reasoning and several asprin (don't do this with a hangover children) I figured it out. I put an extra line 'objNewMail.From = ...' in after the 'objNewMail.To = ...' to fill in the 'from' part that the code needed.
Ha! I'm getting good at this! I might even take it up for a living! Waddya say!?
Thanks for all the help Fuzzboxer and for your patience with the delays and my stupidity. You're a star.
Many thanks and warm regards
Martin
Thanks for the new code.
I came across one problem that was easy to solve which was the line 'objNewMail.AttachFile FileName' which should have been 'objNewMail.AddAttachment FileName'.
The other problem an error message that says:
CDO.Message.1 error '8004020d'
At least one of the From or Sender fields is required, and neither was found.
/StoryForm.asp, line 124
The line is: 'objNewMail.Send'
With a bit of reasoning and several asprin (don't do this with a hangover children) I figured it out. I put an extra line 'objNewMail.From = ...' in after the 'objNewMail.To = ...' to fill in the 'from' part that the code needed.
Ha! I'm getting good at this! I might even take it up for a living! Waddya say!?
Thanks for all the help Fuzzboxer and for your patience with the delays and my stupidity. You're a star.
Many thanks and warm regards
Martin
I am looking for a very similar solution for the non-profit I work for.
I am pretty new at ASP too, did you ever get this worked out?
I am pretty new at ASP too, did you ever get this worked out?
ASKER
Hi stone5150
Yeah, got it all sorted.
Here's the link fuzzboxer gave http://www.motobit.com/help/scptutl/sa271.htm. You need to download the .zip file 'Pure ASP file upload with progress bar'. This will give you the files you need.
Fuzzboxer amended the script to use CDOSYS instead of CDONTS (see the comment near the top of this question by _Stilgar_ as to why).
My script now looks like:
<%
' Sample file Form-Email.asp
' Let's you send one an email with one or more attachments.
' Original code from http://www.motobit.com/help/scptutl/upload.asp
' Alteration of code to use CDOSYS instead of CDONTS by fuzzboxer at Experts Exchange
' See https://www.experts-exchange.com/questions/22482550/Upload-an-image-on-a-form-and-email-it.html
'Global declarations.
'Get temporary folder
Dim ResultHTML
'Create upload form
'Using Huge-ASP file upload
'Dim Form: Set Form = Server.CreateObject("Scrip tUtils.ASP Form")
'Using Pure-ASP file upload
Dim Form: Set Form = New ASPForm %><!--#INCLUDE FILE="_upload.asp"--><%
Server.ScriptTimeout = 1000
'Do not upload data greater than 10MB.
Form.SizeLimit = &HA00000
'Progress bar window will receive the same ID.
Form.UploadID = Request.QueryString("Uploa dID")'{/b}
Const fsCompletted = 0
If Form.State = fsCompletted Then 'Completted
ResultHTML = ProcessForm
ElseIf Form.State > 10 then
Const fsSizeLimit = &HD
Select case Form.State
case fsSizeLimit: ResultHTML = "<br><Font Color=red>Source form size (" & Form.TotalBytes & "B) exceeds form limit (" & Form.SizeLimit & "B)</Font><br>"
case else ResultHTML = "<br><Font Color=red>Some form error.</Font><br>"
end Select
End If
if request.QueryString("Actio n") = "Cancel" then
ResultHTML = "<br><b>Upload was cancelled</b>"
end if
Function TempFolder()
Dim FS
Set FS = CreateObject("Scripting.Fi leSystemOb ject")
'Get temporary folder
TempFolder = FS.GetSpecialFolder(2) & "\emailtemp"
End Function
Sub DeleteFile(FileName)
Dim FS
Set FS = CreateObject("Scripting.Fi leSystemOb ject")
FS.DeleteFile FileName
End Sub
Function ProcessForm
Dim eName, eAddress, ePostcode, ePhone, eMail, eStory
'get source form fields - From, To, Subject, Message etc.
eName = Form("Name")
eAddress = Form("Address")
ePostcode = Form("PostCode")
ePhone = Form("PhoneNumber")
eMail = Form("EmailAddress")
eStory = Form("Story")
Dim HTML
HTML = "<br><span style='color:red'>Server-s ide ASP script accepted source form with fields and files and email object was created. "
HTML = HTML & "<br>From: <b>" & eName & "</b>"
HTML = HTML & "<br>Address: <b>" & eAddress & "</b>"
HTML = HTML & "<br>Postcode: <b>" & ePostcode & "</b>"
HTML = HTML & "<br>Phone: <b>" & ePhone & "</b>"
HTML = HTML & "<br>Email: <b>" & eMail & "</b>"
HTML = HTML & "<br>Story: <b>" & eStory & "</b>"
Dim objNewMail, File, FileName
'Create a new email message
Set objNewMail = CreateObject("CDO.Message" )
objNewMail.To = "name@domain.com" ' Change this to your recipient
objNewMail.From = "name@domain.com" ' Change this to your poster
objNewMail.Subject = "From the Website" ' Change this to your subject line
'Save source files to temporary folder
'Add these files to the new e-mail
HTML = HTML & "<br>Attachments:"
For Each File In Form.Files.Items
'If source file is specified.
If Len(File.FileName) > 0 Then
HTML = HTML & "<br> " & File.Name & ": <b>" & File.FileName & ", " & File.Length \ 1024 & "kB</b>"
FileName = TempFolder & "\" & File.FileName
File.SaveAs FileName
objNewMail.AddAttachment FileName
End If
Next
'Send the new email
objNewMail.HtmlBody = HTML
objNewMail.Send
Response.Redirect("ThankYo u.asp") ' Change this to your page name
Set objNewMail=nothing
'delete temporary files
For Each File In Form.Files.Items
If Len(File.FileName) > 0 Then
FileName = TempFolder & "\" & File.FileName
on error resume next
DeleteFile FileName
End If
Next
HTML = HTML & "</Font><br>"
ProcessForm = HTML
End Function
'{b}get an unique upload ID for this upload script and progress bar.
Dim UploadID, PostURL
UploadID = Form.NewUploadID
'Send this ID as a UploadID QueryString parameter to this script.
PostURL = Request.ServerVariables("S CRIPT_NAME ") & "?UploadID=" & UploadID'{/b}
%>
Alter the requisite parts of 'Function ProcessForm' and 'Dim HTML' to reflect your form. My form has the 'name' fields:
Name
Address
PostCode
PhoneNumber
EmailAddress
Story
Don't forget to alter the parts I've marked to your details.
Regards
Martin
Yeah, got it all sorted.
Here's the link fuzzboxer gave http://www.motobit.com/help/scptutl/sa271.htm. You need to download the .zip file 'Pure ASP file upload with progress bar'. This will give you the files you need.
Fuzzboxer amended the script to use CDOSYS instead of CDONTS (see the comment near the top of this question by _Stilgar_ as to why).
My script now looks like:
<%
' Sample file Form-Email.asp
' Let's you send one an email with one or more attachments.
' Original code from http://www.motobit.com/help/scptutl/upload.asp
' Alteration of code to use CDOSYS instead of CDONTS by fuzzboxer at Experts Exchange
' See https://www.experts-exchange.com/questions/22482550/Upload-an-image-on-a-form-and-email-it.html
'Global declarations.
'Get temporary folder
Dim ResultHTML
'Create upload form
'Using Huge-ASP file upload
'Dim Form: Set Form = Server.CreateObject("Scrip
'Using Pure-ASP file upload
Dim Form: Set Form = New ASPForm %><!--#INCLUDE FILE="_upload.asp"--><%
Server.ScriptTimeout = 1000
'Do not upload data greater than 10MB.
Form.SizeLimit = &HA00000
'Progress bar window will receive the same ID.
Form.UploadID = Request.QueryString("Uploa
Const fsCompletted = 0
If Form.State = fsCompletted Then 'Completted
ResultHTML = ProcessForm
ElseIf Form.State > 10 then
Const fsSizeLimit = &HD
Select case Form.State
case fsSizeLimit: ResultHTML = "<br><Font Color=red>Source form size (" & Form.TotalBytes & "B) exceeds form limit (" & Form.SizeLimit & "B)</Font><br>"
case else ResultHTML = "<br><Font Color=red>Some form error.</Font><br>"
end Select
End If
if request.QueryString("Actio
ResultHTML = "<br><b>Upload was cancelled</b>"
end if
Function TempFolder()
Dim FS
Set FS = CreateObject("Scripting.Fi
'Get temporary folder
TempFolder = FS.GetSpecialFolder(2) & "\emailtemp"
End Function
Sub DeleteFile(FileName)
Dim FS
Set FS = CreateObject("Scripting.Fi
FS.DeleteFile FileName
End Sub
Function ProcessForm
Dim eName, eAddress, ePostcode, ePhone, eMail, eStory
'get source form fields - From, To, Subject, Message etc.
eName = Form("Name")
eAddress = Form("Address")
ePostcode = Form("PostCode")
ePhone = Form("PhoneNumber")
eMail = Form("EmailAddress")
eStory = Form("Story")
Dim HTML
HTML = "<br><span style='color:red'>Server-s
HTML = HTML & "<br>From: <b>" & eName & "</b>"
HTML = HTML & "<br>Address: <b>" & eAddress & "</b>"
HTML = HTML & "<br>Postcode: <b>" & ePostcode & "</b>"
HTML = HTML & "<br>Phone: <b>" & ePhone & "</b>"
HTML = HTML & "<br>Email: <b>" & eMail & "</b>"
HTML = HTML & "<br>Story: <b>" & eStory & "</b>"
Dim objNewMail, File, FileName
'Create a new email message
Set objNewMail = CreateObject("CDO.Message"
objNewMail.To = "name@domain.com" ' Change this to your recipient
objNewMail.From = "name@domain.com" ' Change this to your poster
objNewMail.Subject = "From the Website" ' Change this to your subject line
'Save source files to temporary folder
'Add these files to the new e-mail
HTML = HTML & "<br>Attachments:"
For Each File In Form.Files.Items
'If source file is specified.
If Len(File.FileName) > 0 Then
HTML = HTML & "<br> " & File.Name & ": <b>" & File.FileName & ", " & File.Length \ 1024 & "kB</b>"
FileName = TempFolder & "\" & File.FileName
File.SaveAs FileName
objNewMail.AddAttachment FileName
End If
Next
'Send the new email
objNewMail.HtmlBody = HTML
objNewMail.Send
Response.Redirect("ThankYo
Set objNewMail=nothing
'delete temporary files
For Each File In Form.Files.Items
If Len(File.FileName) > 0 Then
FileName = TempFolder & "\" & File.FileName
on error resume next
DeleteFile FileName
End If
Next
HTML = HTML & "</Font><br>"
ProcessForm = HTML
End Function
'{b}get an unique upload ID for this upload script and progress bar.
Dim UploadID, PostURL
UploadID = Form.NewUploadID
'Send this ID as a UploadID QueryString parameter to this script.
PostURL = Request.ServerVariables("S
%>
Alter the requisite parts of 'Function ProcessForm' and 'Dim HTML' to reflect your form. My form has the 'name' fields:
Name
Address
PostCode
PhoneNumber
EmailAddress
Story
Don't forget to alter the parts I've marked to your details.
Regards
Martin
Thanks =o)
I can get the upload part to work, but when I try to go to the page with your script I get a blank page.
I can get the upload part to work, but when I try to go to the page with your script I get a blank page.
ASKER
Do you mean you get a blank page after you've filled in the form and submitted it?
Martin
I mean I type in URL to the page with that code on it and I get a blank page.
ASKER
In what way do you type in the URL?
Is it on your computer or on a web server?
Is it on your computer or on a web server?
It is on a web server, set up with the directory to run asp stuff.
I tried it on my own IIS 6 machine and on a hosted site and I get the same thing.
A blank page with only this when I do view source.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=windows-1252"></HE AD>
<BODY></BODY></HTML>
A blank page with only this when I do view source.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=windows-1252"></HE
<BODY></BODY></HTML>
ASKER
Hi S
Truly speaking, everything you've asked for help on really should've been a new question but as we've come this far, post your page and I'll have a look. I don't promise to cure the problem but I'll give it a go.
Regards
Martin
Truly speaking, everything you've asked for help on really should've been a new question but as we've come this far, post your page and I'll have a look. I don't promise to cure the problem but I'll give it a go.
Regards
Martin
You're right, it is getting to the point you should be getting points for this now.
https://www.experts-exchange.com/questions/22509545/Upload-an-image-on-form-and-email-it.html
https://www.experts-exchange.com/questions/22509545/Upload-an-image-on-form-and-email-it.html
Stilgar.