Forum Moderators: phranque

Message Too Old, No Replies

ASP Mail Issue

AspSmartUpload Problems

         

trishac

6:37 pm on Jun 7, 2005 (gmt 0)

10+ Year Member



I am having difficulties getting a web form to work with an attachment. The form was first setup as an ASP form that e-mailed the results to an e-mail address. But now, I need to enhance the form to allow for attachments to be uploaded and then the results and the attachment(s) to be e-mailed. I know that I need a mail program, so I have installed AspSmartUpload on our server. I installed it and ran a test, and it seems to work. But I'm having difficulties getting the form to work, and I'd REALLY appreciate any help that anyone could provide. I found this thread to be helpful: [webmasterworld.com...] However, to be frank, I was an English major hired as a Technical Writer for my company and am now having to figure out all web coding on my own without any training. So I wasn't able to follow the thread close enough to determine how to fix my issues. Would anyone be willing to point me in the right direction?

Thanks so much in advance for any advice or help provided!

Here's my original form that works other than getting the file to upload:

<%
tType=request("Type")

email=request.form("email")

select case tType
case else
msgName=name
msgTo=email
msgBody=""
CloseOnSend=True
end select

MailerError=""
if request.form("send")>"" then
cr=chr(13)& chr(10)
name=request.form("name")
email=request.form("email")
subject=request.form("subject")

select case request("Type")

<snip>

CoID=false
%>
<html>
<head><LINK REL="stylesheet" TYPE="text/css" HREF="../_includefiles/mainstyle.css">
<title>Customer Support Case Email Form</title>
<snip>

</head>
<body bgcolor="#FFFFFF">
<form NAME="mainform" method="post" onsubmit="validate();" runat="server"><% if tType="" then %>
<table width="550">
<tr><td>
<h2><img src="../images/logo.gif"><br><br><br>
Customer Support Case Email Form</h2>
Complete the following form to enter a support case with Cheetah's Customer Support Department.

<snip>

<tr><td><input type="submit" value="Send" name="send" runat="server"> <input type="Reset" value="Clear"></td></tr></table>
<% end if %></form>
</body>
</html>

[edited by: txbakers at 3:32 am (utc) on June 8, 2005]
[edit reason] snipped long code [/edit]

trishac

6:38 pm on Jun 7, 2005 (gmt 0)

10+ Year Member



Here's my lame attempt at altering the code to make it all work. This file is called support_case_eform.html.

<html>
<head><LINK REL="stylesheet" TYPE="text/css" HREF="../_includefiles/mainstyle.css">
<title>Customer Support Case Email Form</title>

<snip>

</head>
<body bgcolor="#FFFFFF">
<form NAME="mainform" method="post" onsubmit="validate();" runat="server" ENCTYPE="multipart/form-data" ACTION="/scripts/aspSmartUpload/supportformresults.asp">
<table width="550">
<tr><td>
<h2><img src="../images/logo.gif"><br><br><br>
Customer Support Case Email Form</h2>
Complete the following form to enter a support case with Cheetah's Customer Support Department.

<snip>

</form>
</body>
</html>

And here's the asp file:

<%
tType=request("Type")

email=request.form("email")

MailerError=""
if request.form("send")>"" then
cr=chr(13)& chr(10)
name=request.form("name")
email=request.form("email")
subject=request.form("subject")

<snip>

<%
Set myRecordSet = Server.CreateObject("adodb.recordset")
myRecordSet.Open
Set myUpload = Server.CreateObject("aspSmartUpload.SmartUpload")
myUpload.DownloadField(myRecordSet("FILE"))
myRecordSet.Close
Set myRecordSet = nothing
%>

[edited by: txbakers at 3:43 am (utc) on June 8, 2005]
[edit reason] snipped long code [/edit]

txbakers

3:47 am on Jun 8, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi and welcome to the Webmaster World! I had to snip your post - all that code wasn't really needed to help identify your issue and would actually drive people away instead of having them look at it.

You mentioned you were not really a Tech person, but it looks like you did a great job with that. The ASP Upload component and related code is not something for beginners, so Kudos to you for getting as far as you did!

As for your issue, I think - but not certain - that the problem lies in the red lines above. When you send the enctype as binary and use the component, the "request" object goes away and you have to use the "upload" object.

You discovered that in the "impossible" vs. "possible" section of your code and I think it carries through with all the ASP code.

One trick to doing something like this is to comment out the actual Executes and Redirects so that you stay on that page. Then, put in a whole bunch of "Response.Write" lines to check your variables and functions. You might find out which one is failing and not sending a value that you expect. Give that a try and let us know WHEN you solve it. I'm confident that you will, you have a great start here.

trishac

1:46 pm on Jun 8, 2005 (gmt 0)

10+ Year Member



I was so encouraged to get a reply so quickly, and thanks for the information. But after working hours on this, I'm worse off than I was. Can someone post some code that works so I can look at it and try to figure it out from there? The samples that ASPSmartUpload provided don't do what I want, and since I'm limited on my coding, I don't know how to change them. I basically want an asp form that sends an e-mail with the form fields and attachments. I'm sorry I'm so dense. The instructions are just beyond me, but if I can look at code that works, I can usually figure it out. Thanks so much!

txbakers

10:20 pm on Jun 8, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



without posting the entire code, here is what my mailer code looks like, with an attachment. this one I'm taking from a filesystem rather than the upload.

In your case, I would use the ASPUpload to put the file on the server first, then retrieve it as I'm doing. I might be using a different mailing component that you are, so the syntax might be different:

var Mailer = Server.CreateObject("SMTPsvg.Mailer");
Mailer.FromName = "myname";
Mailer.FromAddress = "me@example.com";
Mailer.RemoteHost = "mail.xample.com";
Mailer.Subject = "the subject";
Mailer.AddRecipient( "The Recipient","you@example.com");
Mailer.BodyText = "Text Here";
Mailer.AddAttachment ("E:\\directory\\file.txt");
Mailer.SendMail();
Mailer = null;

I'm also doing it in javascript, yours might be in VB so again, the syntax would be different.

Hope that helps you. For your form, everything looked fine. don't try to mix your operations. first get the file uploaded to the server. Then worry about the email,then the attachment.

A Computer program or script can only process on command at a time. If you need to, write it so it processes one and stop, then add another, etc. etc.

trishac

4:26 pm on Jun 9, 2005 (gmt 0)

10+ Year Member



Thank you so much. I know I'm getting closer. I'm using Javascript too, and my mailer was very similar, but I was missing the Mailer.AddAttachment part. So I see that you have yours set to file.txt. Do I have to specify a file name? I plan to have a lot of customers using the file upload option, and they could be uploading Word, Excel, or graphics files.

Thanks again! It feels good to get a little closer to making this work. Next, I'm going to work on getting the code in the right order, like you suggested.

trishac

6:31 pm on Jun 9, 2005 (gmt 0)

10+ Year Member



Okay, I added the response.write and it all works. When I take them out and try to have the form e-mailed to me, I get a page can't be displayed error. I know the form is set up correctly. But I doubt the ASP page is right. (I've listed it below.) And I really owe you all beers for all your help so far!

Any suggestions on this?

<%
' Variables
' *********

' Object creation
' ***************
Set mySmartUpload = Server.CreateObject("aspSmartUpload.SmartUpload")

' Upload
' ******
mySmartUpload.Upload

'Now lets get some values for the variables from the form
MyCompany = Request.Form("MyCompany")
etc.

'Now lets build the body of the email from the data in the form
MyBody = MyBody & "Company Name: "& MyCompany & vbcrlf
etc.

'Now lets put the variables and other information we need into the mailing script
mailTo= Request.Form("mailTo") & "name@example.com"
Subject= "Customer Support Case Email Form"
Message= Request.Form("Message")

Set Mailer = Server.CreateObject ("SMTPsvg.Mailer")
Mailer.FromName = MyName
Mailer.FromAddress = MyEmail
Mailer.RemoteHost = "mail.example.com"
Mailer.Subject = "Customer Support Case Email Form"
Mailer.BodyText = MyBody
Mailer.AddRecipient mailTo, mailTo
Mailer.ReturnReceipt = false
Mailer.ConfirmRead = false

if Mailer.SendMail then
Response.Redirect "thankyou.asp"
ELSE

' If there was an error in sending an email, this code will output to the screen
Set Mailer = Nothing
Response.Write "Your message was not sent."
Response.Write Mailer.Response
END IF
%>

[edited by: txbakers at 2:09 pm (utc) on June 10, 2005]
[edit reason] examplified, trimmed [/edit]

txbakers

2:08 pm on Jun 10, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi, you're not using Javascript for the ASP coding. You're using VB.

Also, please don't post your personal emails/domain here.

The only other thing I can suggest is to not do so much at the same time. Get the form to submit with only field, and only one line of text.

You need to isolate you error.

ALSO, use Internet Explorer and do the following:

Tools > Internet Options > Advanced >
UNCHECK "Show friendly HTTP error messages"

this will give you the line number of the first error the script encounters and you can start debugging.