Solved

Upload an image on a form and email it

Posted on 2007-03-30
25
775 Views
Last Modified: 2008-02-07
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
0
Comment
Question by:Pantyboy
  • 11
  • 6
  • 6
  • +1
25 Comments
 
LVL 14

Expert Comment

by:_Stilgar_
ID: 18822754
All you have to do is upload the image, save it as a file (or keep it in a memory buffer), and then email it as an attachment. CDO is deprecated in Win2003 servers, so IO suggest using 3rd party email component such as JMail.

Stilgar.
0
 
LVL 1

Author Comment

by:Pantyboy
ID: 18822798
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
0
 
LVL 14

Expert Comment

by:_Stilgar_
ID: 18822821
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.
0
 
LVL 9

Expert Comment

by:fuzzboxer
ID: 18823163
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.
0
 
LVL 9

Expert Comment

by:fuzzboxer
ID: 18823169
Sorry, I meant to give you this link to the email code: http://www.motobit.com/help/scptutl/sa271.htm
0
 
LVL 1

Author Comment

by:Pantyboy
ID: 18823279
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
0
 
LVL 1

Author Comment

by:Pantyboy
ID: 18849286
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
0
 
LVL 9

Expert Comment

by:fuzzboxer
ID: 18850130
Post your code and I'll check it out.
0
 
LVL 1

Author Comment

by:Pantyboy
ID: 18850993
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.ActiveConnection = MM_CCC_STRING
TemplateFooter_cmd.CommandText = "SELECT * FROM qryCharityContactDetails"
TemplateFooter_cmd.Prepared = 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.ActiveConnection = 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("ScriptUtils.ASPForm")
'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("UploadID")'{/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("Action") = "Cancel" then
      ResultHTML = "<br><b>Upload was cancelled</b>"
end if

Function TempFolder()
      Dim FS
  Set FS = CreateObject("Scripting.FileSystemObject")
  'Get temporary folder
  TempFolder = FS.GetSpecialFolder(2) & "\emailtemp"
End Function

Sub DeleteFile(FileName)
      Dim FS
  Set FS = CreateObject("Scripting.FileSystemObject")
      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.NewMail")
  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>&nbsp;" & 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("SCRIPT_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/mainTemplate.dwt.asp" codeOutsideHTMLIsLocked="false" -->
<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/ChristianLewisTrust.css" rel="stylesheet" type="text/css" media="screen"></link>
<link rel="shortcut icon" href="favicon.ico"></link>
<script language="javascript" type="text/javascript" src="Scripts/ChristianLewisTrust.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:url(system/logoBackground.gif)">&nbsp;</td>
            <td width="490" height="80" align="center" style="background-image:url(system/logoBackground.gif)"><img src="system/ChristianLewisTrustLogoFull.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:url(system/menuBackground.gif)"><!-- InstanceBeginEditable name="leftColumnHeading" --><%=(Headers.Fields.Item("Section").Value)%><!-- InstanceEndEditable --></td>
            <td width="490" class="NavBarSeperator" style="background-image:url(system/menuBackground.gif)"><a href="default.asp" class="NavBar">Home</a> | <a href="FamilyServices.asp" class="NavBar">Family Services</a> | <a href="DonationsAndFundraising.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.asp" -->
<!-- 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="MessageAndStoryConfirm.asp?story=Family%20Story">-->
<form method="post" ENCTYPE="multipart/form-data" 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")%>"></textarea></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("PhoneNumber")%>" /></td>
      </tr>
      <tr>
      <td align="left">Email Address:</td>
      <td align="left"><input name="EmailAddress" type="text" class="inputBox" value="<%=Form("EmailAddress")%>" /></td>
      </tr>
      <tr>
      <td colspan="2">Your Story:</td>
      </tr>
      <tr>
      <td colspan="2"><textarea name="Story" rows="10" class="inputBox" value="<%=Form("Story")%>"></textarea></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','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,width=350,height=200')
 
  return true;
}
</SCRIPT>
                              <!-- InstanceEndEditable --></td>
                        </tr>
        </table></td>
      </tr>
      <tr>
      <td width="200" id="leftColContent" style="border:#2B3D8F thin solid">&nbsp;</td>
            <td width="490" align="center" class="footer" style="border:#2B3D8F thin solid"><a href="DonationsAndFundraising.asp" class="footerLink">Home</a> | <a href="FamilyServices.asp" class="footerLink">Family Services</a> | <a href="DonationsAndFundraising.asp" class="footerLink">Donations 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"><%=(TemplateFooter.Fields.Item("CharityName").Value)%>, <%=(TemplateFooter.Fields.Item("Address").Value)%> - Tel: <%=(TemplateFooter.Fields.Item("TelephoneNumber").Value)%>  - Fax: <%=(TemplateFooter.Fields.Item("FaxNumber").Value)%><br />
      Charity Registration Number: <%=(TemplateFooter.Fields.Item("CharityNumber").Value)%> - &copy; <%=(TemplateFooter.Fields.Item("CharityName").Value)%>
<br />
<span class="smallerFont"><b><%=(TemplateFooter.Fields.Item("CharityName").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
0
 
LVL 9

Expert Comment

by:fuzzboxer
ID: 18851331
Replace that line with this:
  objNewMail.Htmlbody = HTML
  objNewMail.Send
0
 
LVL 1

Author Comment

by:Pantyboy
ID: 18851923
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
0
 
LVL 9

Expert Comment

by:fuzzboxer
ID: 18851945
Sorry, I should have made it objNewMail.Body = HTML since you are using CDONTS.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 1

Author Comment

by:Pantyboy
ID: 18852172
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
0
 
LVL 9

Accepted Solution

by:
fuzzboxer earned 500 total points
ID: 18852515
You are probably on a server that doesn't support CDONTS (like stated above).

Use this code, starting at line 102 (after the comment "Create a new email message"), to replace everything up to objNewMail.Send:

  Set objNewMail = CreateObject("CDO.Message")
  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>&nbsp;" & 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.HtmlBody = HTML
  objNewMail.Send
  Set objNewMail=nothing
0
 
LVL 1

Author Comment

by:Pantyboy
ID: 18857136
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
0
 
LVL 9

Expert Comment

by:Bob Stone
ID: 18895459
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?
0
 
LVL 1

Author Comment

by:Pantyboy
ID: 18895966
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 http://www.experts-exchange.com/Web_Development/Software/Macromedia_Dreamweaver/Q_22482550.html

'Global declarations.
'Get temporary folder
Dim ResultHTML

'Create upload form
'Using Huge-ASP file upload
'Dim Form: Set Form = Server.CreateObject("ScriptUtils.ASPForm")
'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("UploadID")'{/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("Action") = "Cancel" then
      ResultHTML = "<br><b>Upload was cancelled</b>"
end if

Function TempFolder()
      Dim FS
  Set FS = CreateObject("Scripting.FileSystemObject")
  'Get temporary folder
  TempFolder = FS.GetSpecialFolder(2) & "\emailtemp"
End Function

Sub DeleteFile(FileName)
      Dim FS
  Set FS = CreateObject("Scripting.FileSystemObject")
      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-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("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>&nbsp;" & 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("ThankYou.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("SCRIPT_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
0
 
LVL 9

Expert Comment

by:Bob Stone
ID: 18900679
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.
0
 
LVL 1

Author Comment

by:Pantyboy
ID: 18901934

Do you mean you get a blank page after you've filled in the form and submitted it?

Martin
0
 
LVL 9

Expert Comment

by:Bob Stone
ID: 18901961
I mean I type in URL to the page with that code on it and I get a blank page.
0
 
LVL 1

Author Comment

by:Pantyboy
ID: 18902246
In what way do you type in the URL?

Is it on your computer or on a web server?
0
 
LVL 9

Expert Comment

by:Bob Stone
ID: 18902531
It is on a web server, set up with the directory to run asp stuff.
0
 
LVL 9

Expert Comment

by:Bob Stone
ID: 18902554
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"></HEAD>
<BODY></BODY></HTML>
0
 
LVL 1

Author Comment

by:Pantyboy
ID: 18904512
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
0
 
LVL 9

Expert Comment

by:Bob Stone
ID: 18905171
You're right, it is getting to the point you should be getting points for this now.
http://www.experts-exchange.com/Web_Development/Software/Macromedia_Dreamweaver/Q_22509545.html
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I still run into .cgi files every now and then. In some instances, I actually prefer the simplicity of a .cgi script to other options. Since I use DreamWeaver extensively, what I needed was a way to open .cgi scripts in Dreamweaver. And I wanted to …
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now