|
I'm going to copy/paste the contents of a sendmail script I wrote here for you to use. If you want to send an html email with it, simply make a an html file and put it in the same directory as the form. All the elements of the form should be marked in the html email like this: [$formfieldname$]
The sendmail script will load the email template, replace all of the [$xxx$] keys with the contents from the submitted form, where xxx is the name of the submitted form field. You don't have to use an email template, and if you don't, the script will generate a plain-text email for you. Let me know if anything doesn't seem to function correctly.
<%
'---------------------------------------------------------------------------------------------------
'FORM MAIL SCRIPT
'----------------
'usage:
'<form ACTION="sendmail.asp" ...>
'
'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.
'---------------------------------------------------------------------------------------------------
option explicit
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("redirect")
mailto = request.form("mailto")
cc = request.form("cc")
bcc = request.form("bcc")
mailfrom = request.form("mailfrom")
subject = request.form("subject")
message = request.form("message")
template = request.form("template")
testmode = lcase(request.form("testmode"))="yes"
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("CDONTS.NewMail")
if usetemplate and lcase(request.form("html")) = "yes" then
msg.bodyformat = 0 '(html)
msg.mailformat = 0 '(mime)
end if
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"
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,"<br>"))
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
msg.body = body
if testmode then
if lcase(request.form("html")) = "yes" then
response.write "<pre>" & 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 & string(80,"-") & "</pre>"
response.write body
else
response.write "<html><head><title>Sendmail.asp Test Mode</title></head><body><pre>" & 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**</pre></body></html>"
end if
else
msg.send
response.redirect redir
end if
set msg = nothing
%>
NATHAN RIDLEY
Web Application Developer
generalgherkin@yahoo.com
|
|
|
|
|
That's great thanks!
I'll give it a go.
The man who smiles when things go wrong has thought of someone he can blame it on.
If you tell a man there are 300 billion stars in the universe, he'll believe you. But if you tell him a bench has just been painted, he'll have to touch it to be sure.
|
|
|
|
|
What you want to do is iterate through all the forms on a field, getting their name and value.
An ex-co-worker wrote this handy script which works similarly to the sendmail script the other chap posted. It is ASP.NET but the concepts are similar in ASP.
regards,
Paul Watson
Bluegrass
South Africa
Brian Welsch wrote:
"blah blah blah, maybe a potato?" while translating my Afrikaans.
Crikey! ain't life grand?
|
|
|
|
|
Thanks Paul
I'll try it out and see how it goes.
The man who smiles when things go wrong has thought of someone he can blame it on.
If you tell a man there are 300 billion stars in the universe, he'll believe you. But if you tell him a bench has just been painted, he'll have to touch it to be sure.
|
|
|
|
|
What happens when "global.asa" (classical ASP) and "global.asax" (ASP.NET) both resides in the same folder?
|
|
|
|
|
The ASP application will use the .asa file and the ASP.NET application will use the .asax file. They should not interfere with each other as they are different machine processes.
(Honestly I have never tried but if the above is not true and they do interfere, then bad Microsoft, bad! )
regards,
Paul Watson
Bluegrass
South Africa
Brian Welsch wrote:
"blah blah blah, maybe a potato?" while translating my Afrikaans.
Crikey! ain't life grand?
|
|
|
|
|
But, M$ has been known to be bad =)
|
|
|
|
|
Paul is right though - the two files can co-exist in the same folder, and global.asa will be used for ASP while global.asax will be used for ASP.NET.
|
|
|
|
|
MS is not bad always... it sometimes works fine.
What u said was and 'is' right. It will work simultaneously for corresponding ASP / ASP.NET application.
'IT WORKS' for me!!!
I was born intelligent Education ruined me!.
|
|
|
|
|
How can you enumerate "keys" of an Application object? The following script works, but "i" isn't as descriptive as the actual name of the "key".
For i=1 to Application.Contents.Count
Response.Write(i & ":" & Application.Contents(i) & "<br>")
Next
Thanks!
|
|
|
|
|
For Each key As String In Application.Contents.AllKeys
Trace.WriteLine(Application.Contents(key))
Next
|
|
|
|
|
|
Can you return a dictionary object from a function written in VBScript? Here's what I'm trying to accomplish:
<%
Function PopulateAList()
Dim objList
Set objList=Server.CreateObject("Scripting.Dictionary")
PopulateAList = objList 'Error, having trouble with this.
End Function
%>
<%
Dim objList
objList = PopulateAList()
for each item in objList.items
Response.Write "Hey!"
Next
%>
Thanks.
|
|
|
|
|
Yes, like this:
function x
dim o : set o = createobject("scripting.dictionary")
'do stuff to o
set x = o
end function
dim objlist
set objlist = x()
NATHAN RIDLEY
Web Application Developer
generalgherkin@yahoo.com
|
|
|
|
|
Thanks. My mistake. Got it fixed now.
|
|
|
|
|
CillyMe wrote:
PopulateAList = objList 'Error, having trouble with this.
Your problem is that you aren't using the Set keyword. In VB/VBScript, you have to use the Set keyword to assign an object to a variable or property.
Set PopulateAList = objList
|
|
|
|
|
Hi there!
There is this thing I want to do: I have a webpage where the user may select one or more items in a list. Obviously the listbox allows multiple selection of the items, but you have to press Ctrl or Shift keys to do it, which is not very intuitive or friendly for inexperienced users. So, I think adding checkboxes for each item in the list would be a good solution, but don't know how to do it
I've read about using a datagrid instead of a listbox, but again, don't know how.
Could someone help me out with this??
Thanks in advance!!!
|
|
|
|
|
You can't do it to the listbox specifically, you'd have to create a scrollable div and stcik a list of checkboxes inside it. the posted result will be the same, as long as you make sure all the checkboxes have the same name.
<div style="width:160px; height:200px; border:2px inset; overflow:auto;">
this item<br>
this item<br>
this item<br>
</div>
NATHAN RIDLEY
Web Application Developer
generalgherkin@yahoo.com
|
|
|
|
|
great!!! that's just what I needed
Thanks a lot!!! it worked perfectly
|
|
|
|
|
This looks good.... I give u a '5'
I was born intelligent Education ruined me!.
|
|
|
|
|
I guess the same is used in hotmail... to collect the email addresses in the 'to/cc/bcc' field and add them to the address book after you send the mail.
I was born intelligent Education ruined me!.
|
|
|
|
|
Nathan Ridley wrote:
this item
this item
this item
Since the checkboxes can have more than one checked, how do you tell when multiple boxes are checked?
|
|
|
|
|
If you called your checkboxes "chk", you'd do it like this:
dim obj
for each obj in request.form("chk")
'do something with obj
next
NATHAN RIDLEY
Web Application Developer
email: nathan @ netlab.com.au
[remove the spaces before and after the @ symbol]
|
|
|
|
|
if you are doing a public web site, and you are asked to do a dhtml pull down menu, will you support ns4 and other old browser?
supporting ns4 is somewhere a very daunting task to me, I have downloaded several .net menu control and none of them work in ns4...
i use my ns4 yo browse to www.aspalliance.com, it doesn't work..
So, if you are a developer, how to you test your web site for browser compatability? what browsers are you using to test?
BEN BEN
|
|
|
|
|
My opinion is that NS4 is sufficiently obsolete and unused these days that supporting it is more trouble than it's worth.
I think you can get away with supporting a minimum of IE5.0 and NS6.
NATHAN RIDLEY
Web Application Developer
generalgherkin@yahoo.com
|
|
|
|