?
Solved

Attachment with an e-mail form in ASP

Posted on 2003-03-06
12
Medium Priority
?
522 Views
Last Modified: 2007-12-19
Hi, I'm new to asp and i'm looking for the ASP form which sends file attachments(in my case it's jpeg files) from my site. I searched in lots of websites , but they haven't got anything similar. If it's possible i need
this kinda form:

Your name:
Recipient (better few) e-mail:
Your message:
Submit      Reset


I think that's it. I would be very appreciate if anyone relies to me.
Thank you.
0
Comment
Question by:Kouras
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 2
  • 2
  • +2
12 Comments
 
LVL 15

Expert Comment

by:gladxml
ID: 8085608
Kouras,

Try to check out the link.. might help...

http://www.4guysfromrolla.com/webtech/faq/Email/faq3.shtml
0
 

Accepted Solution

by:
Ice69devil earned 225 total points
ID: 8086780
Hi Kouras,
You can automate the sending of email by using the CDONTS object. Like the example below:

<%
'instantiate an object of CDONTS.NewMail
Set trialMail = Server.CreateObject("CDONTS.NewMail")

'set the TO attribute, recipient address, separate multiple with semi-colons
trialMail.To = "<email address>@<email server>.com"

'From attribute is the reply email you want recipient to see
trialMail.From = "<replying email>@<mail server>.com"

'Enter Subject here
trialMail.Subject = "<subject>"

'Jus set Body Format to 0 for HTML msg and 1 for plain text msg
trialMail.BodyFormat=0

'Email message to be delivered
trialMail.Body="This is for Kouras, Ice"

'The file to be attached, provide the physical path in case of mistakes
Call trialmail.AttachFile("d:\asp stuff\emailtrial.asp","emailtrial.asp")

'Finally send the mail by calling Send method then set the email object to nothing

trialMail.Send
Set trialMail=nothing
%>
0
 

Expert Comment

by:Ice69devil
ID: 8087010

i included two asp files for u to begin with. The first is the form and the second is for the processing and sending of emails.
i wrote these two pages in a rush did not include any error checking so please check and debug
but the idea is there :)

p/s: pardon the sloppy layout cos hurry :p

<!--Emailform.asp-->

<%@ Language=VBScript %>
<HTML>
<HEAD>
</HEAD>
<BODY>

<FORM ACTION="SENDEMAIL.ASP" METHOD="POST">
     Your Name <INPUT TYPE="text" NAME="SENDER" ID="SENDER"><bR>
     Your Email <INPUT TYPE="text" NAME="MyEMAIL" ID="MyEMAIL"><br>
     Recipients Email <input type="text" NAME="RECIPIENT" ID="RECIPIENT"><BR>
     Separate multiple recipients with semicolon;<br>
     Subject <input type="text" NAME="SUBJECTTITLE" ID="SUBJECTTITLE"><BR>
     Message <textarea></textarea><Br>
     <input type="submit" NAME="SUBMIT" ID=SUBMIT" VALUE="Send Mail">
</FORM>
</BODY>
</HTML>

-----------------------------------------------
<!--sendemail.asp-->

<%@ Language=VBScript %>
<%

FUNCTION SENDMAIL(BYVAL MyEMAIL, BYVAL RecipientEMAIL, BYVAL SubjectTITLE, BYVAL MESSAGE, BYVAL AttachFilePATH, BYVAL SENDER)
     Set trialMail = Server.CreateObject("CDONTS.NewMail")
     trialMail.To = RecipientEMAIL
     trialMail.From = MyEMAIL
     trialMail.Subject =  SubjectTITLE
     trialMail.BodyFormat=0
     trialMail.Body=MESSAGE & vbCrLf & "from SENDER
     Call trialmail.AttachFile(AttachFilePATH)
     trialMail.Send
     Set trialMail=nothing
END FUNCTION

SENDER=Request.FORM("SENDER")
RECIPIENT=Request.Form("RECIPIENT")
SubjectTITLE=Request.Form("SubjectTITLE")
MESSAGE=Request.Form("MESSAGE")
MyEMAIL=Request.Form("MyEMAIL")

SENDMAIL(MyEMAIL, RecipientEMAIL, SubjectTITLE, MESSAGE, "D:/MY DOCUMENTS/MY PICTURES/MYPICTURE.JPG", SENDER)


%>
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Expert Comment

by:Ice69devil
ID: 8089922
pls correct this mistake....
"from SENDER
to
"from" & SENDER
0
 

Author Comment

by:Kouras
ID: 8090547
Hi, guys. Thank you for quick reply.

 Ice69devil do you know why i'm receiving this error:


Error Type:
Microsoft VBScript compilation (0x800A0414)
Cannot use parentheses when calling a Sub
/........./SENDEMAIL.ASP, line 24, column 78
SENDMAIL(MyEMAIL, RecipientEMAIL, SubjectTITLE, MESSAGE, "submit.jpg", SENDER)

What do i have to do with parentheses?

Thanx again
0
 

Expert Comment

by:Ice69devil
ID: 8092628
Oh i'm sorry, that's a mistake.

Please change
SENDMAIL(MyEMAIL, RecipientEMAIL, SubjectTITLE, MESSAGE, "D:/MY DOCUMENTS/MY PICTURES/MYPICTURE.JPG", SENDER)

to either

CALL SENDMAIL(MyEMAIL, RecipientEMAIL, SubjectTITLE, MESSAGE, "D:/MY DOCUMENTS/MY PICTURES/MYPICTURE.JPG", SENDER)

or,

SENDMAIL MyEMAIL, RecipientEMAIL, SubjectTITLE, MESSAGE, "D:/MY DOCUMENTS/MY PICTURES/MYPICTURE.JPG", SENDER

The reason is because when calling subs in VB, it is a syntactical error if we include the parameters within brackets.
Functions that do not return a value are also similar to Sub, which means even if u begin a procedure with FUNCTION.....END FUNCTION, but function itself does not have a return call, or an assignment of values to the function name, it'll be regarded as a SUB....END SUB

If you want to call a sub you must either use CALL or do without the parentheses. Personally i prefer to use CALL as it makes the code more readable.

I hope my explanation is clear...:)

Cheers

IcE

0
 

Author Comment

by:Kouras
ID: 8092701
Hi, Ice69devil. It doesn't work. Now I'm receiving the following error:

Error Type:
(0x80004005)
Unspecified error
/.........../sendmail.asp, line 11


The code is:

<%@ Language=VBScript %>
<%

FUNCTION SENDMAIL(BYVAL MyEMAIL, BYVAL RecipientEMAIL, BYVAL SubjectTITLE, BYVAL MESSAGE, BYVAL AttachFilePATH, BYVAL SENDER)
    Set trialMail = Server.CreateObject("CDONTS.NewMail")
    trialMail.To = RecipientEMAIL
    trialMail.From = MyEMAIL
    trialMail.Subject =  SubjectTITLE
    trialMail.BodyFormat=0
    trialMail.Body=MESSAGE & vbCrLf & "from" & SENDER
    Call trialmail.AttachFile(AttachFilePATH)   <--Line11
    trialMail.Send                                    
    Set trialMail=nothing
END FUNCTION

SENDER=Request.FORM("SENDER")
RECIPIENT=Request.Form("RECIPIENT")
SubjectTITLE=Request.Form("SubjectTITLE")
MESSAGE=Request.Form("MESSAGE")
MyEMAIL=Request.Form("MyEMAIL")

CALL SENDMAIL(MyEMAIL, RecipientEMAIL, SubjectTITLE, MESSAGE, "scan.jpg", SENDER)



%>

Do i have instead of  AttachFilePATH   put the image name?

Even if i put i get the same unspecified error.

Thanx, anyway.
0
 

Expert Comment

by:johslind
ID: 8093229
I think there is a problem with the path for the attached file. Here is a script that would work with ChiliASP:

<%
thefile = Server.mapPath("some.txt")
Set objMail = Server.CreateObject( "CDONTS.NewMail" )
objMail.To = "receiver@domain.com"
objMail.From = "name@yourdomain.com"
objMail.Subject = "Some subject"
objMail.Body = "A file is attached"
objMail.Host = "localhost"
objMail.AttachFile(thefile)
objMail.Send
Set objMail = Nothing
%>

The definition of a host seems to be necessary only with ChiliASP.

Please note the first line where Server.mapPath is used to get the absolute path of your attached file. If your script and the file are not both in the root directory, it will have to be defined somewhat differently.

You will have to change the definition of From and To.
0
 

Expert Comment

by:Ice69devil
ID: 8099796
Yes AttachFilePATH should be the location of ur image file.
If the image resides in the same directory as ur .HTM and .ASP files, the path would simply be

"thispicture.jpg".

Else u will have to include the correct path, assuming the image resides in MY Documents, it'll be instead

"C:\My Documents\thispicture.jpg"

Cheers

IcE
0
 

Expert Comment

by:johslind
ID: 8101081
To: Ice69devil.
Yes, I am sure that path would work on my own computer. But arent' we talking about remote servers?
I have just tested your suggestion (to name the attachment file by its own name, without path). With my Chili-server, it does not work, although the script is in the same directory.
So I still think it is safest to use the Server.MapPath().
Johs.
0
 

Expert Comment

by:Ice69devil
ID: 8103217
Dear Johslind, if the script is in the same directory as the .jpg file, it'll definitely work, this is because it works for me. Server.MapPath() is also fine, but because my reply was intended for Kouras, who is a fresh to ASP so let's not complicate things with too much information.

Cheers

IcE
0
 

Expert Comment

by:west7213
ID: 8120238
Hey guys!  I think all you codes are correct, but one important thing I need to mention: he need to install SMTP service before he can use CDONTS. I used to have the same problem before, and now the problem is gone!

Kouras, in case you don't know, here is the instruction to install SMTP service: control panel -> add/remove program -> windows setup -> IIS -> detail -> check SMTP service.

:)wESt
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

764 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