I have a select field within a form (below) that allows the user to select a specific 'agent' in which they want the form to be emailed to. The code below displays the correct name and email for the agents.
<select name="to" class="select-box">
<option value="">Send message to</option>
<?php if(isset($agents) && $agents):
if(!is_array($agents)) { $agents = array($agents); }
foreach($agents as $agent):
$agent_post = get_post($agent);
$email = sanitize_email(get_post_meta( $agent, '_meta_email', true ));
$mailto[] = $email;
echo '<option value="'.$email.'">'.wp_kses_data($agent_post->post_title).'</option>';
endforeach;
endif;
?>
</select>
... now is when things start to get tricky. The PHP to actually use the selected email is not working properly.
$to = $_REQUEST['to'];
if(!$to) $to = nt_get_option('property', 'contact_email', get_bloginfo('admin_email'));
The second line acts as a backup plan if no email address is selected, however it's being used even if the user has selected a specific agent. Any suggestions on what I'm missing?