We help IT Professionals succeed at work.

Use Form Value To Derive Email Address

Ryan Rood
Ryan Rood asked
on
Medium Priority
298 Views
Last Modified: 2013-12-13
Hi,

I am trying to make a form that will pull the value from the form to send to that specific email address. Please see attached code. So the value from "emailto" needs to somehow be referenced in the form post under the recipients value.

Thanks in advance,
Ryan
<html>
<head>
	<title>Request For Scheduling Consideration</title>
</head>
 
<body OnLoad="document.TimeOffReq.LastName.focus();" background="background.png">
 
<form method="post" action="NewUserReq.php" name="TimeOffReq" onSubmit="return checkEmail(this)">
    <input type="hidden" name="env_report" value="REMOTE_HOST,REMOTE_ADDR,HTTP_USER_AGENT,AUTH_TYPE,REMOTE_USER">
    <input type="hidden" name="required" value="FirstName:Your First Name,LastName:Your Last Name,DateRequested:Date Required">
	<input type="hidden" name="subject" value="Request For Scheduling Consideration" />
	 <input name="recipients" value="emailto" type="hidden" />
	
	<font face="verdana">
	<table width="400" border="0" cellpadding="0" cellspacing="0" align="center">
	<div align="center">
	<img src="logo.png" alt="">
	<br>
	
	<tr>
	<td>
		<select name="emailto" size="1">
		<option value="a@a.com" selected>Ryan - DT</option>
		<option value="b@b.com">Carolyn - DT</option>
		<option value="c@c.com">Doug - LA</option>
		<option value="d@d.com">Blair - HP</option>
		<option value="e@e.com">Randy - LE</option>
		</select> 
	</td>
	</tr>
	
	<tr>
		<td align="center" colspan="2"><strong><br><u>Requestor Information</u></strong></td>
	</tr>
    <tr>
        <td><br>Last Name:</td>
        <td><br>
								<input type="text" name="LastName" onChange="javascript:this.value=this.value.toUpperCase();">
        </td>
    </tr>
	<tr>
        <td>First Name:</td>
        <td><input type="text" name="FirstName" onChange="javascript:this.value=this.value.toUpperCase();">
        </td>
    </tr>
	
	<tr>
	<td>
	<br>Date Requested: </td>
	<td>
	<input type="text" name="DateRequested" onChange="javascript:this.value=this.value.toUpperCase();">
	</td>
	</tr>
		
    <tr>
		<td colspan="2" align="center"><br>
        Comments / Special Requests:<br>
        <textarea name="comments" rows="7" cols="49" style="overflow:hidden;"></textarea>
        </td>
						</tr>
	<br><br>
    <tr>
        <td><br><input type="submit" value="Submit" /></td>
        <td><br><input type="reset" value="Reset" /></td>
    </tr></div>
	</font>
   </table>
</form>
</body>
</html>

Open in new window

Comment
Watch Question

You mean you want a PHP script for doing this?
You can start with this
NewUserReq.php
 
<?php
$emailto = $_POST["emailto"];
//use the variable $emailto so send the mail
?>

Open in new window

Author

Commented:
Sorry, I have a form processor now, it is a PHP script from Tectite. It requires the value be fed in through this variable. I want it to send to the email address that is selected when the form is submitted.
I think if your php script is expecting a post variable by the name "emailto" then your html should work. Have you named your script NewUserReq.php? Are you getting any error?

Author

Commented:
emailto is my variable, i need to pass  <input name="recipients" value="emailto" type="hidden" /> to the php script in this format ... except it generally wants an actual email address in "value=""". How can i submit a variable that will change when the form is processed and passed?
Simple just name your select box as recipients and remove the input field like this
<html>
<head>
        <title>Request For Scheduling Consideration</title>
</head>
 
<body OnLoad="document.TimeOffReq.LastName.focus();" background="background.png">
 
<form method="post" action="NewUserReq.php" name="TimeOffReq" onSubmit="return checkEmail(this)">
    <input type="hidden" name="env_report" value="REMOTE_HOST,REMOTE_ADDR,HTTP_USER_AGENT,AUTH_TYPE,REMOTE_USER">
    <input type="hidden" name="required" value="FirstName:Your First Name,LastName:Your Last Name,DateRequested:Date Required">
        <input type="hidden" name="subject" value="Request For Scheduling Consideration" />
        
        <font face="verdana">
        <table width="400" border="0" cellpadding="0" cellspacing="0" align="center">
        <div align="center">
        <img src="logo.png" alt="">
        <br>
        
        <tr>
        <td>
                <select name="recipients" size="1">
                <option value="a@a.com" selected>Ryan - DT</option>
                <option value="b@b.com">Carolyn - DT</option>
                <option value="c@c.com">Doug - LA</option>
                <option value="d@d.com">Blair - HP</option>
                <option value="e@e.com">Randy - LE</option>
                </select> 
        </td>
        </tr>
        
        <tr>
                <td align="center" colspan="2"><strong><br><u>Requestor Information</u></strong></td>
        </tr>
    <tr>
        <td><br>Last Name:</td>
        <td><br>
                                                                <input type="text" name="LastName" onChange="javascript:this.value=this.value.toUpperCase();">
        </td>
    </tr>
        <tr>
        <td>First Name:</td>
        <td><input type="text" name="FirstName" onChange="javascript:this.value=this.value.toUpperCase();">
        </td>
    </tr>
        
        <tr>
        <td>
        <br>Date Requested: </td>
        <td>
        <input type="text" name="DateRequested" onChange="javascript:this.value=this.value.toUpperCase();">
        </td>
        </tr>
                
    <tr>
                <td colspan="2" align="center"><br>
        Comments / Special Requests:<br>
        <textarea name="comments" rows="7" cols="49" style="overflow:hidden;"></textarea>
        </td>
                                                </tr>
        <br><br>
    <tr>
        <td><br><input type="submit" value="Submit" /></td>
        <td><br><input type="reset" value="Reset" /></td>
    </tr></div>
        </font>
   </table>
</form>
</body>
</html>

Open in new window

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
Well it worked, I thought I had tried that before I posted but something must have been wrong.

Thanks!
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.