email selection on a form

S

scpirin

How can I create a dropdown menu that offers different email addresses and
when submit is clicked, emails the form results to the specified email
address?

I am pretty sure HTML itself won't do it. Am willing to incorporate ASP or
PHP.

thanks,
scpirin
 
A

Adrienne

How can I create a dropdown menu that offers different email addresses
and when submit is clicked, emails the form results to the specified
email address?

I am pretty sure HTML itself won't do it. Am willing to incorporate
ASP or PHP.

thanks,
scpirin

ASP - Page 1
<form method="post" action="form2.asp">
<fieldset>
<label for="email">Email Address: </label>
<!-- If you are getting the email addresses from a database, open a
recordset here -->
<select name="email" id="email">
<!-- Begin looping through your recordset -->
<option value="">Select an Email Address</option>
<option value="(e-mail address removed)">[email protected]</option>
<option value="(e-mail address removed)">[email protected]</option>
<!-- end looping -->
</select>
<p style="text-align:center"><input type="submit" value="Submit" /></p>
</fieldset>
</form>

Page 2

<% dim email

email = request.form("email")

newmail.to = email
newmail.body = "Your message here"
newmail.send

%>

Adjust page 2 to whatever mailing system you are using, CDO, Aspmail, etc.
 
T

Toby A Inkster

scpirin said:
How can I create a dropdown menu that offers different email addresses and
when submit is clicked, emails the form results to the specified email
address?

I am pretty sure HTML itself won't do it. Am willing to incorporate ASP or
PHP.

You are right. HTML won't do it.

In PHP, it would be something like this:

Form:

<form action="formhandler.php" method="POST">
<fieldset>
<legend>E-mail Form</legend>
<label>To: <select name="who">
<option value="a">Al</option>
<option value="b">Bob</option>
<option value="c">Chaz</option>
</select></label><br>
<label>Subject: <input name="what1"></label><br>
<label>Body:<br> <textarea name="what2"></textarea></label>
</fieldset>
</form>

formhandler.php:

<?php
$who = $_POST['who'];
if ($who == 'a') { $to = '(e-mail address removed)'; }
else if ($who == 'b') { $to = '(e-mail address removed)'; }
else ($who == 'c') { $to = '(e-mail address removed)'; }
$subj = $_POST['what1'];
$body = $_POST['what2'];
if ( mail($to,$subj,$body) ) {
header('Location: thanks.html');
} else {
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<title>Error</title>
<body><h1>Error</h1><p>An unspecified error occurred.</p></body>
<?
}
?>
 
S

scpirin

Toby A Inkster said:
scpirin said:
How can I create a dropdown menu that offers different email addresses and
when submit is clicked, emails the form results to the specified email
address?

I am pretty sure HTML itself won't do it. Am willing to incorporate ASP or
PHP.

You are right. HTML won't do it.

In PHP, it would be something like this:

Form:

<form action="formhandler.php" method="POST">
<fieldset>
<legend>E-mail Form</legend>
<label>To: <select name="who">
<option value="a">Al</option>
<option value="b">Bob</option>
<option value="c">Chaz</option>
</select></label><br>
<label>Subject: <input name="what1"></label><br>
<label>Body:<br> <textarea name="what2"></textarea></label>
</fieldset>
</form>

formhandler.php:

<?php
$who = $_POST['who'];
if ($who == 'a') { $to = '(e-mail address removed)'; }
else if ($who == 'b') { $to = '(e-mail address removed)'; }
else ($who == 'c') { $to = '(e-mail address removed)'; }
$subj = $_POST['what1'];
$body = $_POST['what2'];
if ( mail($to,$subj,$body) ) {
header('Location: thanks.html');
} else {
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<title>Error</title>
<body><h1>Error</h1><p>An unspecified error occurred.</p></body>
<?
}
?>


Thanks much guys.....
Will work on both formats and see if I can get it to work........

scpirin
 
D

Default User

scpirin said:
Thanks much guys.....
Will work on both formats and see if I can get it to work........


Make sure your mail handling script doesn't take in an address from the
form and use it willy-nilly. Otherwise spammers can exploit your script
to their benefit and likely your sorrow.




Brian Rodenborn
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,053
Latest member
BrodieSola

Latest Threads

Top