PDA

View Full Version : AspEmail Attachment details...



-=j0nnyr0773n=-
02 Nov 2005, 07:22 PM
Hey all,

I have created an AspEmail form that works flawlessly. Also on the same page I have created two fields that you can browse your local pc and click upload to upload two files to a directory called /upload on the web server via ASPupload. Now I want to be able to attach those two specific files to the mail form when it is submitted to the server. My predicament is that all the documentation I have come across says you need to specifically state the exact path to the filenames to be attached eg...



Mail.AddAttachment="/upload/filename.txt"


Now that is fine, I understand that but in my situation users will be uploading resumes and headshots to the server from their own pc's and the filenames and types will be different everytime. The locations will be the same but the names and types different. Is there a way to tell the form to attach the two last uploaded files to the message? Here is a sample of my code:



<% @LANGUAGE=VBSCRIPT %>

<HTML>
<BODY>
<%
strHost = "mail.accuwebhosting.biz"
If Request("SUBMIT") <> "" Then
Set Mail = Server.CreateObject("Persits.MailSender")
Mail.Host = strHost

Mail.From = Request("email")
Mail.FromName = Request("email")
Mail.AddAddress "webform@selfcenteredproductions.com"

Mail.Subject = Request("Self Centered Productions Webform Inquiry")
Mail.Body = "First Name: " & request("firstname") & vbCrlf & "Last Name: " & request("lastname") & vbCrlf & "Company Name: " & request("company") & vbCrLf & "Trade: " & request("trade") & vbCrLf & "Home Phone: " & request("telephone") & vbCrLf & "Cell Phone: " & request("cellphone") & vbCrLf & "Location Residing: " & request("location") & vbCrLf & "Comments and Messages: " & request("comments")
strErr = ""
bSuccess = False
On Error Resume Next
Mail.Send
If Err <> 0 Then
strErr = Err.Description
else
bSuccess = True
End If
End If
response.redirect "resume.htm"
%>

</BODY>
</HTML>


Thank you in advance for any insight.

-=j0nnyr0773n=- :D

-=j0nnyr0773n=-
02 Nov 2005, 11:18 PM
I figured it out, here it is in case anyone else wants to know. Instead of making a html form that posts to an .ASP file, just combine the two in one like so. Also there is no need to separately upload the files before attaching them to the message, this code does it all at once, to see the finished product go to http://www.selfcenteredproductions.com/resume.asp :)



<% @LANGUAGE=VBSCRIPT %>


<%
strHost = "mail.accuwebhosting.biz"
Set Upload = Server.CreateObject("Persits.Upload")
Upload.IgnoreNoPost = True

Upload.SaveVirtual "/upload/"

If Upload.Form("SUBMIT") <> "" Then
Set Mail = Server.CreateObject("Persits.MailSender")
Mail.From = Upload.Form("email")
Mail.FromName = Upload.Form("email")
Mail.Host = strHost
Mail.Subject = "Self Centered Productions Webform Inquiry"
Mail.Body = "First Name: " & Upload.Form("firstname") & vbCrlf & "Last Name: " & Upload.Form("lastname") & vbCrlf & "Company Name: " & Upload.Form("company") & vbCrLf & "Trade: " & Upload.Form("trade") & vbCrLf & "Home Phone: " & Upload.Form("telephone") & vbCrLf & "Cell Phone: " & Upload.Form("cellphone") & vbCrLf & "Location Residing: " & Upload.Form("location") & vbCrLf & "Comments and Messages: " & Upload.Form("comments")
Mail.AddAddress "webform@selfcenteredproductions.com"

If Not Upload.Files("Attachment") Is Nothing Then
Mail.AddAttachment Upload.Files("Attachment").Path
Mail.AddAttachment Upload.Files("Attachment1").Path
End If

Mail.Send
Response.Redirect "success.htm"
End If
%>

<HTML>
<HEAD>
<TITLE>Self Centered Productions - Mission Statement</TITLE>

<STYLE>

body {background-color:#000000; color:#FFFFFF; font-family:arial;}


</STYLE>
</HEAD>

<BODY>
<TABLE border="0" width="725" cellpadding="0" cellspacing="0" align="center">
<TR>
<TD align="center" valign="top">
<TABLE border="0" width="725">
<TR>
<TD align="center" valign="top">
<IMG src="images/toplogo.gif">
</TD>
</TR>
<TR>
<TD align="center">
<HR color="#3366FF" width="660">
</TD>
</TR>

<TR>
<TD align="center">
<IMG src="images/cast_crew.gif">
</TD>
</TR>
<TR>
<TD>&nbsp;</TD>
</TR>
<TR>
<TD align="center">
<FORM action="resume.asp" method="post" ENCTYPE="multipart/form-data">
<TABLE border="0" cellpadding="3" cellspacing="0" width="725">
<TR>
<TD>First Name:</TD>
<TD align="right"><INPUT TYPE="text" NAME="firstname" SIZE="15" maxlength="40"></TD>
<TD>&nbsp;</TD>
<TD>Last Name:</TD>
<TD align="right"><INPUT TYPE="text" NAME="lastname" SIZE="15" maxlength="40"></TD>
</TR>
<TR>
<TD>Company Name:</TD>
<TD align="right"><INPUT TYPE="text" NAME="company" SIZE="15" maxlength="100"></TD>
<TD>&nbsp;</TD>
<TD>Trade:</TD>
<TD align="right"><INPUT TYPE="text" NAME="trade" SIZE="15" maxlength="50"></TD>
</TR>
<TR>
<TD>Home Phone Number:</TD>
<TD align="right"><INPUT TYPE="text" NAME="telephone" SIZE="15" maxlength="15"></TD>
<TD>&nbsp;</TD>
<TD>E-mail Address:</TD>
<TD colspan="2" align="right"><INPUT TYPE="text" NAME="email" SIZE="15" maxlength="100"></TD>
</TR>
<TR>
<TD>Cell Phone Number:</TD>
<TD align="right"><INPUT TYPE="text" NAME="cellphone" SIZE="15" maxlength="15"></TD>
<TD>&nbsp;</TD>
<TD>Location Residing:</TD>
<TD align="right"><INPUT TYPE="text" NAME="location" SIZE="15" maxlength="100"></TD>
</TR>
<TR>
<TD colspan="5">&nbsp;</TD>
</TR>
<TR>
<TD colspan="2" align="center">Comments and Messages:</TD>
<TD colspan="3" align="center"><TEXTAREA NAME="comments" ROWS="3" COLS="50"></TEXTAREA>
</TR>
<TR>
<TD>Upload Headshot</TD>
<TD><INPUT type="file" name="Attachment"></TD>
<TD>&nbsp;</TD>
<TD>Upload Resume</TD>
<TD><INPUT type="file" name="Attachment1"></TD>
</TR>
<TR>
<TD colspan="5" align="right">
<INPUT TYPE="submit" SUBMIT NAME="SUBMIT" VALUE="Submit Information">
</TD>
</TR>
</TABLE>
</FORM>
</TD>
</TR>


</TD>
</TR>
<TR>
<TD colspan="2">&nbsp;</TD>
<TR>
<TR>
<TD colspan="2">
<TABLE border="0" cellpadding="0" cellspacing="0">
<TR>
<TD align="center" height="100" width="375">
<IMG src="images/homesmall.gif" border="0" name="home"
onMouseover="document.home.src='images/homebig.gif';"
onMouseout="document.home.src='images/homesmall.gif';"
onClick="document.location='index.htm';" style="cursor:pointer;">
</TD>
<TD align="center" width="375">
<IMG src="images/missionsmall.gif" border="0" name="mission"
onMouseover="document.mission.src='images/missionbig.gif';"
onMouseout="document.mission.src='images/missionsmall.gif';"
onClick="document.location='mission.htm';" style="cursor:pointer;">
</TD>
</TR>
</TABLE>
</TD>
</TR>
</TABLE>
</TD>
</TR>
</TABLE>

</BODY>
</HTML>


-=j0nnyr0773n=- :D