|
I've now sorted the basis of a solution to my needs.
Anyone else interested may want to have a look at: www.4guysfromrolla.com/webtech/faq/Email/faq3.shtml (Sending an Email with an Attachment: Taylor). Loads of good stuff on this site for struggling coders.
Once you realise that Taylor's 'objMail' is the same as Nathan's 'msg' you can identify and add the line that's needed to add your attachment to the mail. You'll need to make sure that your web server knows the path to where the file is, so you may want to use WebThang's really useful Path Finder from www.webthang.co.uk.
I wanted to send a reply email back to the form filler with an attachment, so I added a copy of Nathan's code underneath the first (after set msg = nothing), dimensioning a second set of variables (eg. msg2, subject2 etc.. – and following these all the way through to 'set msg2 = nothing %>') so that this second instruction to send an email was aimed back at the sender's address lifted from the form and from some suitable mailfrom address within my domain (your host may be checking that forms are not being misused or hijacked); and added the attachment line 'msg2.attachfile("e:\domains\whatever the rest of the path is...\attachment.pdf")' [remove the apostrophes] in after 'msg2.subject = subject2'.
One thing that took me ages to spot was that there is no '=' between the attachfile and the file path. I just dumped one in there without thinking and it drove me batty before I spotted it!
I've got other stuff that I now want to add to this basic solution to what I need to acheive, and I'm sure there's a lot of cleaning up that could be done; but I find once you can achieve something that works, then you can deconstruct, understand (leave yourself lots of annotations within the code to remind you what each bit is doing) and then improve it by adding the other functionality that you need.
A quiet room with all the family out of the house also helps!!
Hope that helps solve a problem for someone else too.
op
|
|
|
|
|
Been using this as my standard form handler for a couple of years and it's never let me down. Thanks.
Now I'm wondering if I can use this as the basis of a script to return an email with a file attachment to the form filler (based on their selection of a PDF data sheet on the form).
I can see my way through identifying the selected file/s, passing that through and going and getting it via fso, but am stuck on actually attaching it to a reply mail within the existing script.
Or am I looking at a scratch start? Anyone implemented anything similar?
Cheers
op
|
|
|
|
|
Here's the form http://www.f9840.com/sendmail/sampleform.htm. Seems to work OK but don't get the email.
|
|
|
|
|
If the form executes properly and seems to think it has sent the mail but you're not receiving it, I'd suggest looking at the mail server. The script is working fine.
NATHAN RIDLEY
Web Application Developer
email: snowdevil [@] gmail.com
web/blog: www.ersysgroup.com[ ^]
|
|
|
|
|
I've reworked the form to act as it should for me, but when I click 'send', internet explorer just opens the .asp file instead of sending an email and showing the 'thanks.htm' page.
what am I doing wrong here?
maybe I missed something in IIS ?
|
|
|
|
|
Is it possible you're calling it like this:
C:\dev\blah\myform.htm
instead of like this:
http://localhost/mywebsite/myform.htm
Because doing the former will definitely create the problem you described.
NATHAN RIDLEY
Web Application Developer
email: snowdevil [@] gmail.com
web/blog: www.ersysgroup.com[ ^]
|
|
|
|
|
thanks Nathan.
so I've corrected that silly error, and I'm calling my form through http:// now......only now when the 'sendmail_cdo.asp' is called (after hitting the submit button) I get an 'HTTP Error 404 - File or directory not found'.
They're all sitting there ready to go, but the .asp file is supposedly not there.
not sure what I'm missing.
|
|
|
|
|
I am also getting the 404 error. Any help would be greatly appreciated (utter newb here).
|
|
|
|
|
I had named my text area 'message' as soon as I changed this it worked ok, drives you insane sometimes doesn't it.
|
|
|
|
|
Hi,
using the downloads here I have created a webpage with 4 single line textfields, a list, and a multi line textfield, I also created a template. It all works apart from not returning the multi line textfield data. Any ideas where I am going wrong ?? (using dreamweaver, my first attempt at using a form). Thanks, Steve.
|
|
|
|
|
Where do I insert my smtp server address...?
_____________________________
...and justice for all
APe
|
|
|
|
|
Add the following after msg.from = mailfrom
Dont forget to change 'smtp.server.com'
msg.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing")=2
'Name or IP of remote SMTP server
msg.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") _
="smtp.server.com"
'Server port
msg.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") _
=25
msg.Configuration.Fields.Update
|
|
|
|
|
Installed this script on a GODADDY server with the minimal ASP support. It doesn;t do anything.
Is this likely some GODADDY restriction?
my (Your) script >>
<%
option explicit
'---------------------------------------------------------------------------------------------------
'FORM MAIL SCRIPT
'----------------
'usage:
'
'
'hidden fields:
' redirect - the url to redirect to when the mail has been sent (REQUIRED)
' mailto - the email address of the recipient (separate multiple recipients with commas) (REQUIRED)
' cc - the email address of the cc recipient (separate multiple recipients with commas) (OPTIONAL)
' bcc - the email address of the bcc recipient (separate multiple recipients with commas) (OPTIONAL)
' mailfrom - the email address of the sender (REQUIRED)
' subject - the subject line of the email (REQUIRED)
' message - the message to include in the email above the field values. not used when a template is being used. (OPTIONAL)
' template - specifies a text or html file to use as the email template, relative to the location of the sendmail script. (e.g. ../email.txt)
' A template should reference form fields like this: [$Field Name$]
' html - if this has the value "yes", the email will be sent as an html email. only used if a template is supplied.
' testmode - if this is set to "yes", the email contents will be written to the screen instead of being emailed.
'---------------------------------------------------------------------------------------------------
dim pde : set pde = createobject("scripting.dictionary")
'---------------------------------------------------------------------------------------------------
'PREDEFINED ADDRESSES for the "mailto" hidden field
'if you don't want to reveal email addresses in hidden fields, use a token word instead and specify
'below which email address it applies to. e.g.
'ALSO, in the same way, you can use %mailfrom% to hide the originating email address
pde.add "%contactform%", "myemail@someaddress.com"
pde.add "%salesenquiry%", "anotheremail@someaddress.com"
'---------------------------------------------------------------------------------------------------
function getTextFromFile(path)
dim fso, f, txt
set fso = createobject("Scripting.FileSystemObject")
if not fso.fileexists(path) then
getTextFromFile = ""
exit function
end if
set f = fso.opentextfile(path,1)
if f.atendofstream then txt = "" else txt = f.readall
f.close
set f = nothing
set fso = nothing
getTextFromFile = txt
end function
dim redir, mailto, mailfrom, subject, item, body, cc, bcc, message, html, template, usetemplate, testmode
redir = request.form("http://www.jmm3.biz/default.html")
mailto = request.form("jmmagruder3@sbcglobal.net")
if pde.exists(mailto) then mailto = pde(mailto)
cc = request.form("cc")
bcc = request.form("bcc")
mailfrom = request.form("email")
if mailfrom = "" then mailfrom = pde("%mailfrom%")
subject = request.form("HELPME")
message = request.form("message")
dayphone = request.form("day")
nightphone = request.form("night")
template = request.form("template")
testmode = lcase(request.form("testmode"))="no"
if len(template) > 0 then template = getTextFromFile(server.mappath(template))
if len(template) > 0 then usetemplate = true else usetemplate = false
dim msg : set msg = server.createobject("CDO.Message")
msg.subject = subject
msg.to = mailto
msg.from = mailfrom
if len(cc) > 0 then msg.cc = cc
if len(bcc) > 0 then msg.bcc = bcc
if not usetemplate then
body = body & message & vbcrlf & vbcrlf
else
body = template
end if
for each item in request.form
select case item
case "redirect", "mailto", "cc", "bcc", "subject", "message", "template", "html", "testmode","buyer","seller","fname","lname","day","night","comments"
case else
if not usetemplate then
if item <> "mailfrom" then body = body & item & ": " & request.form(item) & vbcrlf & vbcrlf
else
body = replace(body, "[$" & item & "$]", replace(request.form(item),vbcrlf," "))
end if
end select
next
if usetemplate then 'remove any leftover placeholders
dim rx : set rx = new regexp
rx.pattern = "\[\$.*\$\]"
rx.global = true
body = rx.replace(body, "")
end if
if usetemplate and lcase(request.form("html")) = "yes" then
msg.htmlbody = body
else
msg.textbody = body
end if
if testmode then
if lcase(request.form("html")) = "yes" then
response.write "
" & vbcrlf
response.write "Mail to: " & mailto & vbcrlf
response.write "Mail from: " & mailfrom & vbcrlf
if len(cc) > 0 then response.write "Cc: " & cc & vbcrlf
if len(dayphone) > 0 then response.write "Dayphone: " & day & vbcrlf
if len(bcc) > 0 then response.write "Bcc: " & bcc & vbcrlf
response.write "Subject: " & subject & vbcrlf & string(80,"-") & " "
response.write body
else
response.write "<title>Sendmail.asp Test Mode
" & vbcrlf
response.write "Mail to: " & mailto & vbcrlf
response.write "Mail from: " & mailfrom & vbcrlf
if len(cc) > 0 then response.write "Cc: " & cc & vbcrlf
if len(bcc) > 0 then response.write "Bcc: " & bcc & vbcrlf
response.write "Subject: " & subject & vbcrlf & vbcrlf
response.write string(80,"-") & vbcrlf & vbcrlf & "<span style=""color:blue;"">"
response.write body & "</span>" & vbcrlf & vbcrlf
response.write string(80,"-") & vbcrlf & "**END OF EMAIL** "
end if
else
msg.send
response.redirect redir
end if
set msg = nothing
%>
My html form >
<title>Magruder Web Feedback
<span
style='font-size:20.0pt'> Your Information Will Be Kept CONFIDENTIAL<span
style='font-size:24.0pt'> <span
style='mso-tab-count:1'>
<span
style='font-size:13.5pt'> Please select INTEREST category
<span
style='font-size:18.0pt'>
BUYER
SELLER
<span
style='font-size:13.5pt'>Please provide your email
like abc @hotmail.com
Please provide your
name First
Last
Please provide 1 or more
phones Day<span
style='font-size:13.5pt'>
Night
Please ask a question of state needs
below – PLEASE be specific !
<span
style='mso-tab-count:2'> I will reply as soon as possible. <span
style='mso-spacerun:yes'>
<o:p>
<a
href="http: www.jmm3.biz="" default.html"="">RETURN
Thanks
John
John
|
|
|
|
|
I have been browsing the list, and couldnt find any information on this.
It would be fantastic if there is a way to attach (input type=file) files via form and send through to the specified email using sendmail.
Is this possible?
And if possible, how do I go about doing it?
Thanks!
K
|
|
|
|
|
the sendmail works great is there away instead of sending the form results as an attachment instead of sending them to a html template.
cheers
|
|
|
|
|
i have set up this script on our intranet at work. when i run it in testmode, it does fine, printing the results to my screen. when i use a value of "no" for testmode, it gives me an error with the following info:
Error Type:
CDO.Message.1 (0x80040220)
The "SendUsing" configuration value is invalid.
/sendmail_cdo.asp, line 120
...
Page:
POST 302 bytes to /sendmail_cdo.asp
any help would be greatly appreciated...
|
|
|
|
|
Script works great and is much appreciated.
I was trying to set so could send via our email server rather than installing SMTP on web server.
I found code to do it in a vbs script
but not sure if can use or where to use in this script.
Here was the code...and it does work in the script i took it from...but wanted to use it with this script and the forms.
Any ideas??
Will this work in this script and in place of what?
Thanks in advance
' Send by connecting to port 25 of the SMTP server.
Dim iMsg
Dim iConf
Dim Flds
Dim strHTML
Const cdoSendUsingPort = 2
set iMsg = CreateObject("CDO.Message")
set iConf = CreateObject("CDO.Configuration")
Set Flds = iConf.Fields
' Set the CDOSYS configuration fields to use port 25 on the SMTP server.
With Flds
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = cdoSendUsingPort
'ToDo: Enter name or IP address of remote SMTP server.
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "10.0.0.200"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 10
.Update
End With
|
|
|
|
|
I am getting an error that says
"Method Not Allowed
The requested method POST is not allowed for the URL /sendmail_cdo.asp."
I have spent HOURS going over the 2 pages involved in using the sendmail code and am near tears. Can anyone please help me with this? The form is located at www.kodonnellsrestaurant.com/k-odonnells-restaurant-jobs.shtml and the sendmail_cdo.asp file is in the root folder along with the page and the .hmtl template. I got the same error when I used the sendmail.asp file.
Please help!!!
Morgan
|
|
|
|
|
Hi,
From what I understand, you're using a Unix/Linux host. I have no experience with *nix systems, and built this script quite a while ago for Microsoft ASP under IIS on Windows. As far as I am aware though, Linux/Unix won't natively process ASP pages without installing the correct software on the server, in your case it would probably be (I think) Chillisoft ASP.
If you do have an ASP processor for your web hosting you're still going to have a problem because the mail sending aspect of the script uses native Windows components, which to my knowledge, don't exist in any form on Unix or Linux.
I would recommend that you either (a) move to a Windows-based host or (b) hunt for a PHP or CGI sendmail script. Do a search for "PHP form mail script".
NATHAN RIDLEY
Web Application Developer
email: snowdevil [@] gmail.com
web/blog: www.ersysgroup.com[^]
|
|
|
|
|
I'm new to ASP and was wondering what i need to add for it send the email to a remote SMTP server.
|
|
|
|
|
This code is great. I'm jsut wondering if there's a way to have multiple mailto: address possible based on a field selected like City or county by the customer so that the request gets sent to the right email for a quick response. We've got regional people that are better suited to receive this requests than just one large email account.
How would I go about something like that. I'm a newbie with ASP too so this has been a great help!
|
|
|
|
|
Since my ISP doesn't support asp (how archaic!), do you have a script which I can use which doesn't need an interpretor? All I am looking for is to jump to an e-mail which is pre-formatted with the form. I prefer not to place the form on the website.
|
|
|
|
|
Hi,
I'm having a problem running this script on our server. I get the following error:
Server object error 'ASP 0177 : 8007007e'
Server.CreateObject Failed
/sendmail_cdo.asp, line 63
8007007e
Line 63 is: dim msg : set msg = server.createobject("CDO.Message")
I'm fairly new to asp so any help to diagnose the problem would be greatly appreciated.
Thanks, Danielle
|
|
|
|
|
Two things:
1) Try the other asp file; it uses a slightly different method of sending mail.
2) If that doesn't work, your hosting provider has disabled your access to the CDO library to prevent you from sending mail.
NATHAN RIDLEY
Web Application Developer
email: snowdevil [@] gmail.com
web/blog: www.ersysgroup.com[^]
|
|
|
|
|
Nathan, Thanks for such a wonderful script!!! I do some simple webmastering for some small accounts and have been slowly watching servers drop support for CDONTS -- the script that I WAS using for all the various little web forms. It got so bad that I was finally "cheating" and serving the ASP scripts from my server because it would still support CDONTS. Surprise! They upgraded the servers at my host and suddenly a customer (who gets lots of genuine hits on their forms) contacts me that their customers are complaining of failures. I'm a better debugger than a code writer and I've been looking everywhere for a CDOSYS form mail script that actually worked. I found yours, studied over it, and I've updated 3 forms -- all in 4 hours. THANK YOU, THANK YOU, THANK YOU!!!
Tricia
Patricia S. McDonald
www.tgpgraphics.com
Austell, GA, USA
|
|
|
|