Menu
I’m setting up this basic PHP form:
[url]http://incentivo.dreamhosters.com/contact/
When someone selects one of the “My Question is for”
Whatever department they select, can I have the form emailed to that specific email address?
[code=php]$departments = array();
// $departments[] = array('Department Name', '[email protected]');
$departments[] = array('Finance Department', '[email protected]');
$departments[] = array('Main Office', '[email protected]');
$departments[] = array('Billing', '[email protected]');
$departments[] = array('Other', '[email protected]');[/code]
[code=php]<select name="questiondropdown" size="1" class="contactRightPanel">
<option value="-1">-- Select One -- </option>
<?php
foreach ($departments as $id => $info)
{
print('<option value="' . $id . '">' . $info[0] . '</option>' . "n");
}
?>
</select>[/code]
[code=php]if (is_numeric($_REQUEST['questiondropdown']) AND $_REQUEST['questiondropdown'] != '-1' AND array_key_exists($_REQUEST['questiondropdown'], $departments))
{
$email_address_to_send_to = $departments[$_REQUEST['questiondropdown']][1];
}
else
{
// no department selected, or no departments specified in array, or hacking attempt
// error handling goes here
}
[/code]
[code=php]<?php
header("Location: thankyou.html");
if(isset($_POST['submit'])) {
$departments = array();
// $departments[] = array('Department Name', '[email protected]');
$departments[] = array('Finance Department', '[email protected]');
$departments[] = array('Main Office', '[email protected]');
$departments[] = array('Billing', '[email protected]');
$departments[] = array('Other', '[email protected]');
$to = "[email protected]";
$subject = "LoHi Scooters Contact Form";
$first_name = $_POST['firstname'];
$last_name = $_POST['lastname'];
$contact_email = $_POST['emailaddress'];
$phone_1 = $_POST['phone1'];
$address_1 = $_POST['address1'];
$address_2 = $_POST['address2'];
$contact_city = $_POST['city'];
$contact_state = $_POST['state'];
$contact_zipcode = $_POST['zipcode'];
$contact_question = $_POST['questiondropdown'];
$contact_subject = $_POST['subject'];
$contact_message = $_POST['message'];
$preferred_checkbox = $_POST['check[]'];
foreach($_POST['check'] as $value) {
$check_msg .= "Preferred Method of Contact: $valuen";
}
$body = "First Name: $first_namenLast Name: $last_namenE-Mail: $contact_emailnnPhone: $phone_1nAddress 1: $address_1nAddress 2: $address_2nCity: $contact_citynState: $contact_statenZip Code: $contact_zipcodennMy Question is Regarding: $contact_questionnSubject: $contact_subjectn$check_msg nMessage: $contact_messagen";
echo "Data has been submitted to $to!";
mail($to, $subject, $body);
} else {
echo "Please use the form to email us.";
}
?>[/code]
[code=php]if (is_numeric($_REQUEST['questiondropdown']) AND $_REQUEST['questiondropdown'] != '-1' AND array_key_exists($_REQUEST['questiondropdown'], $departments))
{
$email_address_to_send_to = $departments[$_REQUEST['questiondropdown']][1];
}
else
{
// no department selected, or no departments specified in array, or hacking attempt
// error handling goes here
} [/code]
[code=php]mail($to, $subject, $body);[/code]
[code=php]<?php
header("Location: thankyou.html");
if(isset($_POST['submit']))
{
$departments = array();
// $departments[] = array('Department Name', '[email protected]');
$departments[] = array('Finance Department', '[email protected]');
$departments[] = array('Main Office', '[email protected]');
$departments[] = array('Billing', '[email protected]');
$departments[] = array('Other', '[email protected]');
$to = "[email protected]";
if (is_numeric($_REQUEST['questiondropdown']) AND $_REQUEST['questiondropdown'] != '-1' AND array_key_exists($_REQUEST['questiondropdown'], $departments))
{
$to = $departments[$_REQUEST['questiondropdown']][1];
}
$subject = "LoHi Scooters Contact Form";
$first_name = $_POST['firstname'];
$last_name = $_POST['lastname'];
$contact_email = $_POST['emailaddress'];
$phone_1 = $_POST['phone1'];
$address_1 = $_POST['address1'];
$address_2 = $_POST['address2'];
$contact_city = $_POST['city'];
$contact_state = $_POST['state'];
$contact_zipcode = $_POST['zipcode'];
$contact_question = $_POST['questiondropdown'];
$contact_subject = $_POST['subject'];
$contact_message = $_POST['message'];
$preferred_checkbox = $_POST['check[]'];
foreach($_POST['check'] as $value)
{
$check_msg .= "Preferred Method of Contact: $valuen";
}
$body = "First Name: $first_namenLast Name: $last_namenE-Mail: $contact_emailnnPhone: $phone_1nAddress 1: $address_1nAddress 2: $address_2nCity: $contact_citynState: $contact_statenZip Code: $contact_zipcodennMy Question is Regarding: $contact_questionnSubject: $contact_subjectn$check_msg nMessage: $contact_messagen";
echo "Data has been submitted to $to!";
mail($to, $subject, $body);
}
else
{
echo "Please use the form to email us.";
}
?>[/code]
[code=php]header("Location: thankyou.html");[/code]
is in there, but if you leave it in there, the script will obviously not work. ?This goes in your contact form (replacing your current code):
[code=php]<select name="questiondropdown" size="1" class="contactRightPanel">
[/QUOTE]
<option value="-1">-- Select One -- </option>
<?php
foreach ($departments as $id => $info)
{
print('<option value="' . $id . '">' . $info[0] . '</option>' . "n");
}
?>
</select>[/code]
[code=html]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Associação Brasileira Incentivo - Contato</title>
<link media="screen" type="text/css" rel="stylesheet" href="/resources/css/homepage.css"/>
<link media="screen" type="text/css" rel="stylesheet" href="/resources/css/diagram.css"/>
<link media="screen" type="text/css" rel="stylesheet" href="/resources/css/view.css"/>
<script type="text/javascript" src="/resources/scripts/hover.js"></script>
</head>
<body id="quem-somos">
<div id="banner">
<div id="nav-global-container">
<ul id="nav-global">
<li id="nav-contact"><a href="/contact/">Contato</a></li><li>|</li>
<!-- <li id="nav-history"><a href="/historia/">Historiá</a></li><li>|</li> -->
<li id="nav-background"><a href="/quem-somos/">Quem somos</a></li><li>|</li>
<li id="nav-home"><a href="/index.html">Home</a></li>
</ul>
</div>
</div>
<div id="container">
<div id="header">
<h1 id="logo"><a href="/index.html"><img alt="Incentivo" src="/resources/images/logo.png"/></a></h1>
<div id="nav-sub-container">
<ul id="nav-sub">
<li id="first"><div>Programas</div>
<ul>
<li><a href="/bolsa-de-estudo/">Bolsa de Estudo</a></li>
<li><a href="/financas-pessoais/">Finanças Pessoais</a></li>
<li><a href="/preparacao-para-mba/">Preparação para MBA</a></li>
</ul>
</li>
<li><div>Filosofia</div>
<ul>
<li><a href="/passar-adiante/">Passar adiante</a></li>
<li><a href="/successo/">História de successo</a></li>
<li><a href="/voluntarios/">Voluntários</a></li>
</ul>
</li>
<!--
<li id="last"><div>Forums</div>
<ul>
<li><a href="/forums/">Bolsa</a></li>
<li><a href="/forums/">Financas</a></li>
<li><a href="/forums/">MBA</a></li>
</ul>
</li>
-->
</ul>
</div>
</div>
<div id="billboard"><h2>Incentivo</h2></div>
<div id="columnwrap">
<div id="content-main">
<h1>
Contato</h1>
<p><span class="contactLeftPanel">Your comments and concerns are important to us. Please provide the following information so that we can address your needs. We will email a response to you within three business days.</span></p>
<p><span class="contactLeftPanel"><span class="contactAsteriskIndicator">* Indicates required information</span></span></p>
<form method="post" action="/resources/scripts/mailer.php">
<table width="465" height="572" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="465" height="50" align="left" valign="top" class="darkGreyLeftPanel">My Question is for * <br />
<select name="questiondropdown" size="1" class="contactRightPanel">
<option value="-1">-- Select One --</option>
<?php
foreach ($departments as $id => $info)
{
print('<option value="' . $id . '">' . $info[0] . '</option>' . "n");
}
?>
</select>
</td>
</tr>
<tr>
<td width="465" height="45" align="left" valign="top" class="darkGreyLeftPanel">Subject * <br />
<input name="subject" type="text" class="contactRightPanel" size="25" />
</td>
</tr>
<tr>
<td width="465" height="79" align="left" valign="top" class="darkGreyLeftPanel">Message | Comments *<br />
<textarea name="message" cols="75" rows="3" class="contactRightPanel"></textarea></td>
</tr>
<tr>
<td width="465" height="40" align="left" valign="top" class="darkGreyLeftPanel">What is your prefered method of contact? <br />
<table width="465" height="25" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="40" height="25" align="left" valign="middle" class="darkGreyLeftPanel">Email</td>
<td width="40" height="25" align="left" valign="middle" class="darkGreyLeftPanel"><input type="checkbox" name="check[]" value="Email"></td>
<td width="40" height="25" align="left" valign="middle" class="darkGreyLeftPanel">Phone</td>
<td width="40" height="25" align="left" valign="middle" class="darkGreyLeftPanel"><input type="checkbox" name="check[]" value="Phone"></td>
<td width="125" height="25" align="left" valign="middle" class="darkGreyLeftPanel">No Response Required </td>
<td width="195" height="25" align="left" valign="middle" class="darkGreyLeftPanel"><input type="checkbox" name="check[]" value="No Response Required"></td>
</tr>
</table></td>
</tr>
<tr>
<td width="465" height="50" align="left" valign="top" background="images/contact/yourinformation.gif"> </td>
</tr>
<tr>
<td width="465" height="40" align="left" valign="top"><table width="465" height="40" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="182" height="40" align="left" valign="top" class="darkGreyLeftPanel">First Name *
<input name="firstname" type="text" class="contactRightPanel" size="25" />
</td>
<td width="293" align="left" valign="top"><span class="darkGreyLeftPanel">Last Name * <br />
<input name="lastname" type="text" class="contactRightPanel" size="25" />
</span></td>
</tr>
</table></td>
</tr>
<tr>
<td width="465" height="45" align="left" valign="middle" class="darkGreyLeftPanel">Email Address * <br />
<input name="emailaddress" type="text" class="contactRightPanel" size="25" />
</span></td>
</tr>
<tr>
<td width="465" height="43" align="left" valign="top" class="darkGreyLeftPanel">Phone Number * <br />
<input name="phone1" type="text" class="contactRightPanel" size="20" />
</span></td>
</tr>
<tr>
<td width="465" height="40" align="left" valign="top" class="darkGreyLeftPanel">Address #1 (Street number) *<br />
<input name="address1" type="text" class="contactRightPanel" size="55" />
</span></td>
</tr>
<tr>
<td width="465" height="40" align="left" valign="bottom" class="darkGreyLeftPanel">Address #2 (apt #, suite #, etc) * <br />
<input name="address2" type="text" class="contactRightPanel" size="55" />
</span></td>
</tr>
<tr>
<td width="465" height="40" align="left" valign="top"><table width="465" height="44" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="147" height="44" align="left" valign="bottom" class="darkGreyLeftPanel">City *<br />
<input name="city" type="text" class="contactRightPanel" size="20" />
</span></td>
<td width="149" height="44" align="left" valign="bottom" class="darkGreyLeftPanel">State *<br />
<input name="state" type="text" class="contactRightPanel" size="20" />
<br />
</span></td>
<td width="179" height="44" align="left" valign="bottom" class="darkGreyLeftPanel">Zip Code *<br />
<input name="zipcode" type="text" class="contactRightPanel" size="20" />
</span></td>
</tr>
</table></td>
</tr>
<tr>
<td width="465" align="right" valign="bottom"><input type="submit" value="Submit" name="submit" ><br />
</a></td>
</tr>
</table>
</form>
</div>
<div class="sidebar" id="content-related">
[/code]
[code=php]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Associação Brasileira Incentivo - Contato</title>
<link media="screen" type="text/css" rel="stylesheet" href="/resources/css/homepage.css"/>
<link media="screen" type="text/css" rel="stylesheet" href="/resources/css/diagram.css"/>
<link media="screen" type="text/css" rel="stylesheet" href="/resources/css/view.css"/>
<script type="text/javascript" src="/resources/scripts/hover.js"></script>
</head>
<body id="quem-somos">
<div id="banner">
<div id="nav-global-container">
<ul id="nav-global">
<li id="nav-contact"><a href="/contact/">Contato</a></li><li>|</li>
<!-- <li id="nav-history"><a href="/historia/">Historiá</a></li><li>|</li> -->
<li id="nav-background"><a href="/quem-somos/">Quem somos</a></li><li>|</li>
<li id="nav-home"><a href="/index.html">Home</a></li>
</ul>
</div>
</div>
<div id="container">
<div id="header">
<h1 id="logo"><a href="/index.html"><img alt="Incentivo" src="/resources/images/logo.png"/></a></h1>
<div id="nav-sub-container">
<ul id="nav-sub">
<li id="first"><div>Programas</div>
<ul>
<li><a href="/bolsa-de-estudo/">Bolsa de Estudo</a></li>
<li><a href="/financas-pessoais/">Finanças Pessoais</a></li>
<li><a href="/preparacao-para-mba/">Preparação para MBA</a></li>
</ul>
</li>
<li><div>Filosofia</div>
<ul>
<li><a href="/passar-adiante/">Passar adiante</a></li>
<li><a href="/successo/">História de successo</a></li>
<li><a href="/voluntarios/">Voluntários</a></li>
</ul>
</li>
<!--
<li id="last"><div>Forums</div>
<ul>
<li><a href="/forums/">Bolsa</a></li>
<li><a href="/forums/">Financas</a></li>
<li><a href="/forums/">MBA</a></li>
</ul>
</li>
-->
</ul>
</div>
</div>
<div id="billboard"><h2>Incentivo</h2></div>
<div id="columnwrap">
<div id="content-main">
<h1>
Contato</h1>
<p><span class="contactLeftPanel">Your comments and concerns are important to us. Please provide the following information so that we can address your needs. We will email a response to you within three business days.</span></p>
<p><span class="contactLeftPanel"><span class="contactAsteriskIndicator">* Indicates required information</span></span></p>
<form method="post" action="/resources/scripts/mailer.php">
<table width="465" height="572" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="465" height="50" align="left" valign="top" class="darkGreyLeftPanel">My Question is for * <br />
<select name="questiondropdown" size="1" class="contactRightPanel">
<option value="-1">-- Select One --</option>
<?php
foreach ($departments as $id => $info)
{
print('<option value="');
print($id);
print('">');
print($info[0]);
print('</option>');
print("n");
}
?>
</select>
</td>
</tr>
<tr>
<td width="465" height="45" align="left" valign="top" class="darkGreyLeftPanel">Subject * <br />
<input name="subject" type="text" class="contactRightPanel" size="25" />
</td>
</tr>
<tr>
<td width="465" height="79" align="left" valign="top" class="darkGreyLeftPanel">Message | Comments *<br />
<textarea name="message" cols="75" rows="3" class="contactRightPanel"></textarea></td>
</tr>
<tr>
<td width="465" height="40" align="left" valign="top" class="darkGreyLeftPanel">What is your prefered method of contact? <br />
<table width="465" height="25" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="40" height="25" align="left" valign="middle" class="darkGreyLeftPanel">Email</td>
<td width="40" height="25" align="left" valign="middle" class="darkGreyLeftPanel"><input type="checkbox" name="check[]" value="Email"></td>
<td width="40" height="25" align="left" valign="middle" class="darkGreyLeftPanel">Phone</td>
<td width="40" height="25" align="left" valign="middle" class="darkGreyLeftPanel"><input type="checkbox" name="check[]" value="Phone"></td>
<td width="125" height="25" align="left" valign="middle" class="darkGreyLeftPanel">No Response Required </td>
<td width="195" height="25" align="left" valign="middle" class="darkGreyLeftPanel"><input type="checkbox" name="check[]" value="No Response Required"></td>
</tr>
</table></td>
</tr>
<tr>
<td width="465" height="50" align="left" valign="top" background="images/contact/yourinformation.gif"> </td>
</tr>
<tr>
<td width="465" height="40" align="left" valign="top"><table width="465" height="40" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="182" height="40" align="left" valign="top" class="darkGreyLeftPanel">First Name *
<input name="firstname" type="text" class="contactRightPanel" size="25" />
</td>
<td width="293" align="left" valign="top"><span class="darkGreyLeftPanel">Last Name * <br />
<input name="lastname" type="text" class="contactRightPanel" size="25" />
</span></td>
</tr>
</table></td>
</tr>
<tr>
<td width="465" height="45" align="left" valign="middle" class="darkGreyLeftPanel">Email Address * <br />
<input name="emailaddress" type="text" class="contactRightPanel" size="25" />
</span></td>
</tr>
<tr>
<td width="465" height="43" align="left" valign="top" class="darkGreyLeftPanel">Phone Number * <br />
<input name="phone1" type="text" class="contactRightPanel" size="20" />
</span></td>
</tr>
<tr>
<td width="465" height="40" align="left" valign="top" class="darkGreyLeftPanel">Address #1 (Street number) *<br />
<input name="address1" type="text" class="contactRightPanel" size="55" />
</span></td>
</tr>
<tr>
<td width="465" height="40" align="left" valign="bottom" class="darkGreyLeftPanel">Address #2 (apt #, suite #, etc) * <br />
<input name="address2" type="text" class="contactRightPanel" size="55" />
</span></td>
</tr>
<tr>
<td width="465" height="40" align="left" valign="top"><table width="465" height="44" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="147" height="44" align="left" valign="bottom" class="darkGreyLeftPanel">City *<br />
<input name="city" type="text" class="contactRightPanel" size="20" />
</span></td>
<td width="149" height="44" align="left" valign="bottom" class="darkGreyLeftPanel">State *<br />
<input name="state" type="text" class="contactRightPanel" size="20" />
<br />
</span></td>
<td width="179" height="44" align="left" valign="bottom" class="darkGreyLeftPanel">Zip Code *<br />
<input name="zipcode" type="text" class="contactRightPanel" size="20" />
</span></td>
</tr>
</table></td>
</tr>
<tr>
<td width="465" align="right" valign="bottom"><input type="submit" value="Submit" name="submit" ><br />
</a></td>
</tr>
</table>
</form>
</div>
<div class="sidebar" id="content-related">[/code]
0.1.9 — BETA 5.18