Time to dust off the old Form processing script!
For the sake of my sanity, I am going to assume (In other words, make an of you and me) that you already know how to make HTML forms and PHP scripts to process them. This is the code that needs to go into your HTML File:
<select name = "EmailTo">
<option value = "
[email protected]">
[email protected]</option>
<option value = "
[email protected]">
[email protected]</option>
<option value = "
[email protected]">
[email protected]</option>
</select>
In the PHP Script, you just 'trim' it like you would any other form variable:
$EmailTo = Trim(stripslashes($_POST['EmailTo']));
All in all, this is a complete overview of my Source code for a simple email script:
index.htm
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/transitional.dtd">
<head>
<title>Example Email Form</title>
<link href="style.css" rel = "stylesheet" type = "text/css">
</head>
<body>
<form method="POST" action="post.php">
<h1>Example Email Form</h1>
<p>Recipiant Email Address:</p>
<select name = "EmailTo">
<option value = "
[email protected]">
[email protected]</option>
<option value = "
[email protected]">
[email protected]</option>
<option value = "
[email protected]">
[email protected]</option>
</select>
<br>
<p>Subject: <input type="text" name="subj"></p>
<p>Message:</p>
<textarea name = "msg" rows = "20" cols = "40">Enter Message Here</textarea>
<p><input type="submit" name="submit" value="Submit"></p>
<br><br><br><br>
</form>
post.php
<?php
$EmailFrom = "
[email protected]";
$EmailTo = Trim(stripslashes($_POST['EmailTo']));
$Subject = Trim(stripslashes($_POST['subj']));
$Message = Trim(stripslashes($_POST['msg']));
$Body = "";
$Body .= $Message;
$Body .= "\n";
$Success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
if ($Success)
{
echo "Form Submited";
}
else
{
echo "ERROR: UNKNOWN";
}
?>
I have also uploaded the script to my webserver. The email function has been dissabled, but this will show you what it looks like: http://jthomsonmain.server1.cc/dev/examp/mail/mail.htm