javascript_howto thread: how to submit to different email addresss for a form action
I'll tell you what I did and it's pretty handy.
First some background. I needed to create a simple form where the
destination was dependant on a combo drop-down.
In the <head> tag, I placed this code.
<script>
<!--
function emailChange(whichEl) {
var currValue;
currValue = whichEl[whichEl.selectedIndex].value;
if (currValue == "Selection-A") {
document.form.mailTo.value = "Person-A@c...";
}
if (currValue == "Selection-B") {
document.form.mailTo.value = "Person-B@c...";
}
}
// -->
</script>
Then, within the <Form> tag:
I declared a hidden field (mailTo) and set its initial vailue to "". I
went ahead and included a mailFrom also.
Like this.
<form method="POST" action="http://Mail-Send.asp" name="form">
<input type="hidden" name="mailFrom" value="Source@c...">
<input type="hidden" name="mailTo" value="">
And added a combo box referencing to the code in the <head> tag.
<SELECT NAME="Product" onchange="javascript:emailChange(this);">
<OPTION value="Selection-A">Description-A
<OPTION value="Selection-B">Description-B
</SELECT>
Finally, the form submits to ASP page (Mail-Send.asp), using VBScript.
(You could use the Javascript equivalent)
In the <Body> tag, I added:
<%
varMailTo = request.item("mailTo")
varMailFrom = request.item("mailFrom")
%>
I then used CDONTS to send it on it's way.
First a few CONST, in case you need to modify later.
'---- BodyFormat Property ----
Const CdoBodyFormatHTML = 0 ' The Body property is to include
Hypertext Markup Language (HTML).
Const CdoBodyFormatText = 1 ' The Body property is to be exclusively
in plain text (default value).
'---- MailFormat Property ----
Const CdoMailFormatMime = 0 ' The NewMail object is to be in MIME
format.
Const CdoMailFormatText = 1 ' The NewMail object is to be in
uninterrupted plain text (default value).
'---- Importance Property ----
Const CdoLow = 0 ' Low importance
Const CdoNormal = 1 ' Normal importance (default)
Const CdoHigh = 2 ' High importance
'---- AttachFile and AttachURL Methods ----
Const CdoEncodingUUencode = 0 ' The attachment is to be in
UUEncode format (default).
Const CdoEncodingBase64 = 1 ' The attachment is to be in base
64 format.
'''''And finally the meat.'''''
dim htmlText
Set objMail = Server.CreateObject("CDONTS.Newmail")
objMail.From = mailFrom
objMail.To = mailTo
objMail.Subject = "This just in"
objMail.Body = "Hello"
objMail.BodyFormat = CdoBodyFormatHTML
objMail.MailFormat = CdoMailFormatText
objMail.Importance = CdoNormal
objMail.Send
Set objMail = nothing
THAT'S IT. A bit lengthy when you are using a lot of names, but reliable.
Also remember that this will require SMTP setup on your server. Homer
published a pretty good one at ASPToday.com.
Good luck!!!