Kouras
asked on
Attachment with an e-mail form in ASP
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.
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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("CDONT
trialMail.To = RecipientEMAIL
trialMail.From = MyEMAIL
trialMail.Subject = SubjectTITLE
trialMail.BodyFormat=0
trialMail.Body=MESSAGE & vbCrLf & "from SENDER
Call trialmail.AttachFile(Attac
trialMail.Send
Set trialMail=nothing
END FUNCTION
SENDER=Request.FORM("SENDE
RECIPIENT=Request.Form("RE
SubjectTITLE=Request.Form(
MESSAGE=Request.Form("MESS
MyEMAIL=Request.Form("MyEM
SENDMAIL(MyEMAIL, RecipientEMAIL, SubjectTITLE, MESSAGE, "D:/MY DOCUMENTS/MY PICTURES/MYPICTURE.JPG", SENDER)
%>
pls correct this mistake....
"from SENDER
to
"from" & SENDER
"from SENDER
to
"from" & SENDER
ASKER
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
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
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
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
ASKER
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("CDONT S.NewMail" )
trialMail.To = RecipientEMAIL
trialMail.From = MyEMAIL
trialMail.Subject = SubjectTITLE
trialMail.BodyFormat=0
trialMail.Body=MESSAGE & vbCrLf & "from" & SENDER
Call trialmail.AttachFile(Attac hFilePATH) <--Line11
trialMail.Send
Set trialMail=nothing
END FUNCTION
SENDER=Request.FORM("SENDE R")
RECIPIENT=Request.Form("RE CIPIENT")
SubjectTITLE=Request.Form( "SubjectTI TLE")
MESSAGE=Request.Form("MESS AGE")
MyEMAIL=Request.Form("MyEM AIL")
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.
Error Type:
(0x80004005)
Unspecified error
/.........../sendmail.asp,
The code is:
<%@ Language=VBScript %>
<%
FUNCTION SENDMAIL(BYVAL MyEMAIL, BYVAL RecipientEMAIL, BYVAL SubjectTITLE, BYVAL MESSAGE, BYVAL AttachFilePATH, BYVAL SENDER)
Set trialMail = Server.CreateObject("CDONT
trialMail.To = RecipientEMAIL
trialMail.From = MyEMAIL
trialMail.Subject = SubjectTITLE
trialMail.BodyFormat=0
trialMail.Body=MESSAGE & vbCrLf & "from" & SENDER
Call trialmail.AttachFile(Attac
trialMail.Send
Set trialMail=nothing
END FUNCTION
SENDER=Request.FORM("SENDE
RECIPIENT=Request.Form("RE
SubjectTITLE=Request.Form(
MESSAGE=Request.Form("MESS
MyEMAIL=Request.Form("MyEM
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.
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.
<%
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.
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
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
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.
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.
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
Cheers
IcE
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
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
Try to check out the link.. might help...
http://www.4guysfromrolla.com/webtech/faq/Email/faq3.shtml