Q: Passing Strings (email address) from form to PHP I have a php contact form and all works great going to a single address but I'm trying to modify my script to handle a drop down selector, which enables choosing a recipient (which email address to send to).
Here is the part of the code that I have so far in trying to deal with this issue:
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="recipient" id="recipient">
          <p class="text">
            Please select recipient<br>
            <select name="recipient" size="4"
           <?php if (isset($missing)) {
                echo 'value="'.htmlentities($_POST['recipient'], ENT_QUOTES).'"';
            } ?>
            >
                <option value="">Select...</option>
                <option value="1">Artistic Director</option>
                <option value="2">Site Administrator</option>
                <option value="3">Someone else</option>
            </select>
            </p>
          </form>  

            <?php if (array_key_exists('send', $_POST)) {
            // mail processing script
            if ('recipient' == 1) {
                $to = 'soandso@mail.com';
            }
            elseif('recipient' == 2) {
                $to = 'soandso@mail.com';
            }
            elseif('recipient' == 3) {
                $to = 'soandso@mail.com';
            }
            else {
                echo 'Sorry for no recipient';
            }

//then remainder code to process the rest which works fine

I'm sure my problem lies in the calling/getting the value of recipient but I can't figure out where to go from here. 

A: You're trying to do something weird here. It should be:
if ($_POST['recipient'] == 1) {
    $to = 'soandso@mail.com';
}
else if($_POST['recipient'] == 2) {
    $to = 'soandso@mail.com';
}
else if($_POST['recipient'] == 3) {
    $to = 'soandso@mail.com';
}
else {
    echo 'Sorry for no recipient';
}

Of course 'recipient' will never be equal to 1, 2 or 3.
I also noticed the form and the select has the same name 'recipient'. I don't know is that is an issue though. But I would like to address it anyway.

A: Your form name and select name is the same. also you are echoing the post value inside the select. i think it is left over from your previous input box.
try this;
<form action="" method="post" id="getEmail">
<p class="text">Please select recipient<br></p>
<select name="recipient" size="4">
        <option value="">Select...</option>
        <option value="1">Artistic Director</option>
        <option value="2">Site Administrator</option>
        <option value="3">Someone else</option>
     </select>
<input type='hidden' name='do' value='1'>
<input type='sumbit' value='Go'>
</form>  

<?php if (isset($_POST['do'])) {
            // mail processing script
            if ($_POST['recipient'] == 1)$to = 'email1';
else if($_POST['recipient'] == 2)$to = 'email2';
else if($_POST['recipient'] == 3)$to = 'email3';
else echo 'Sorry for no recipient';
}
//echo $to;
//to send mail
$sub = 'Mail from web Form';
$msg = 'My message';
$mail_status= mail($to, $sub, $msg);
if($mail_status){do something on success}; else {do something on failure};
?>


A: This code is working 100% :


(function($) {
            
$('#recipient').on('click', function() {
  $('#recipient-form').submit();
});
            
})(jQuery);
<div id="page">
<?php

$to = '';

if (isset($_POST['recipient'])) :

    
    // mail processing script
    if ($_POST['recipient'] == 1) {
        $to = 'recipient1';
    }
    else if($_POST['recipient'] == 2) {
        $to = 'reciipient2';
    }
    else if($_POST['recipient'] == 3) {
        $to = 'recipient3';
    }
    else {
        $to = 'Sorry for no recipient';
    }
    
    echo $to;
else : ?>


  <form action="" method="post" id="recipient-form">
    <select id="recipient" name="recipient" size="4">
      <option value="">Select...</option>
      <option value="1">Artistic Director</option>
      <option value="2">Site Administrator</option>
      <option value="3">Someone else</option>
    </select>
  </form>
</div>
 

<?php endif; ?>



A: The page in it's (mostly) entirety for clarification purposes hopefully:
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" id="recipient-form">
            <p class="text">
                Please select recipient<br>
  <select id="recipient" name="recipient" size="4">
    <option value="">Select...</option>
    <option value="1">Artistic Director</option>
    <option value="2">Site Administrator</option>
    <option value="3">Someone else</option>
  </select>
  </p>
</form>

                <?php if (array_key_exists('send', $_POST)) {
                // mail processing script
                $to = '';

if ($_POST['recipient']) {


    // mail processing script
    if ($_POST['recipient'] == 1) {
        $to = '';
    }
    else if($_POST['recipient'] == 2) {
        $to = '';
    }
    else if($_POST['recipient'] == 3) {
        $to = '';
    }
    else {
        $to = 'Sorry for no recipient';
    }
}

    $subject = 'Feedback From Website';

    // list expected fields
    $expected = array('name', 'email', 'comments', 'subscribe');
    // set required fields
    $required = array('name', 'email', 'comments');

    // set additional headers
    $headers = 'From: ';

    // set the include
    $process = 'includes/process.inc.php';
    if (file_exists($process) && is_readable($process)) {
        include($process);
    }
    else {
        $mailSent = false;
        mail($me, 'Server Problem', "$process cannot be read", $headers);
    }
}
?>

            <?php 
            if ($_POST && isset($missing) && !empty($missing)) {
            ?>
            <p class="warning">Please complete the missing item(s) indicated.</p>
            <?php
            }
            elseif ($_POST && $link) {
            ?>
            <p class="warning">Sorry, Messages sent that contain links will not be sent.</p>
            <?php
            }
            elseif ($_POST && !$mailSent) {
            ?>
            <p class="warning">Sorry, there was a problem sending your message. Please try again later.</p>
            <?php
            }
            elseif ($_POST && $mailSent) {
            ?>
            <p class="success">Your message has been sent. Thank you for your message!</p>
            <?php } ?>


            <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="contact" id="contact" onSubmit="MM_validateForm('name','','R','email','','RisEmail','comments','','R');return document.MM_returnValue">
            <p>
                <label for="name">Name: <?php
                if (isset($missing) && in_array('name', $missing)) { ?>
                <span class="warning">Please enter your name</span><?php } ?>
                </label>
                <input name="name" type="text" class="textInput" id="name" 
                <?php if (isset($missing)) {
                    echo 'value="'.htmlentities($_POST['name'], ENT_QUOTES).'"';
                    } ?>
                >
              </p>
              <p>
                <label for="email">Email: <?php
                if (isset($missing) && in_array('email', $missing)) { ?>
                <span class="warning">Please enter your email address</span><?php } ?>
                </label>
                <input name="email" type="text" class="textInput" id="email"
                <?php if (isset($missing)) {
                    echo 'value="'.htmlentities($_POST['email'], ENT_QUOTES).'"';
                    } ?>
                >
              </p>
              <p>
                <label for="comments">Message:<?php
                if (isset($missing) && in_array('comments', $missing)) { ?>
                <span class="warning">Please enter your message</span><?php } ?>
                </label>
                <textarea name="comments" id="comments" cols="45" rows="5"><?php 
                    if (isset($missing)) {
                        echo htmlentities($_POST['comments'], ENT_QUOTES);
                    } ?></textarea>
              </p>
              <p>

              <p class="text">
                Please check the box if you would like to sign up for our Mailing List!
                <input type="checkbox" name="subscribe" value="Yes"
                <?php if (isset($missing)) {
                    echo 'value="'.htmlentities($_POST['subscribe'], ENT_QUOTES).'"';
                    } ?>
                >
              </p>

              <p>
                <?php
                    require_once('recaptchalib.php');
                    $publickey = "6Lf3NdQSAAAAAOAwgPGRybLnY175X6k9PJ1F2vHx"; // you got this from the signup page
                    echo recaptcha_get_html($publickey);
                ?>
              </p>
              <p class="last">
                <input type="submit" name="send" id="send" value="Send Message">
              </p>
            </form>

Hopefully having all of it now will help someone come up with the best solution!

A: The entirety again.  I think/hope we're getting closer:
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" id="getEmail">
<p class="text">Please select recipient</p><br>
<select name="recipient" size="4">
        <option value="">Select...</option>
        <option value="1">Artistic Director</option>
        <option value="2">Site Administrator</option>
        <option value="3">Someone else</option>
     </select>
<input type='hidden' name='do' value='1'>
</form>  

<?php 
     if (array_key_exists('send', $_POST)) {
        if (isset($_POST['do'])) {
            // mail processing script
            if ($_POST['recipient'] == 1) { $to = ''; }
            else if($_POST['recipient'] == 2) { $to = ''; }
            else if($_POST['recipient'] == 3) { $to = ''; }
            else echo 'Sorry for no recipient';
            }
    echo $to;




    $subject = 'Feedback From Website';

    // list expected fields
    $expected = array('name', 'email', 'comments', 'subscribe');
    // set required fields
    $required = array('name', 'email', 'comments');

    // set additional headers
    $headers = 'From:';

    // set the include
    $process = 'includes/process.inc.php';
    if (file_exists($process) && is_readable($process)) {
        include($process);
    }
    else {
        $mailSent = false;
        mail($me, 'Server Problem', "$process cannot be read", $headers);
    }
}
?>

            <?php 
            if ($_POST && isset($missing) && !empty($missing)) {
            ?>
            <p class="warning">Please complete the missing item(s) indicated.</p>
            <?php
            }
            elseif ($_POST && $link) {
            ?>
            <p class="warning">Sorry, Messages sent that contain links will not be sent.</p>
            <?php
            }
            elseif ($_POST && !$mailSent) {
            ?>
            <p class="warning">Sorry, there was a problem sending your message. Please try again later.</p>
            <?php
            }
            elseif ($_POST && $mailSent) {
            ?>
            <p class="success">Your message has been sent. Thank you for your message!</p>
            <?php } ?>


            <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="contact" id="contact" onSubmit="MM_validateForm('name','','R','email','','RisEmail','comments','','R');return document.MM_returnValue">
            <p>
                <label for="name">Name: <?php
                if (isset($missing) && in_array('name', $missing)) { ?>
                <span class="warning">Please enter your name</span><?php } ?>
                </label>
                <input name="name" type="text" class="textInput" id="name" 
                <?php if (isset($missing)) {
                    echo 'value="'.htmlentities($_POST['name'], ENT_QUOTES).'"';
                    } ?>
                >
              </p>
              <p>
                <label for="email">Email: <?php
                if (isset($missing) && in_array('email', $missing)) { ?>
                <span class="warning">Please enter your email address</span><?php } ?>
                </label>
                <input name="email" type="text" class="textInput" id="email"
                <?php if (isset($missing)) {
                    echo 'value="'.htmlentities($_POST['email'], ENT_QUOTES).'"';
                    } ?>
                >
              </p>
              <p>
                <label for="comments">Message:<?php
                if (isset($missing) && in_array('comments', $missing)) { ?>
                <span class="warning">Please enter your message</span><?php } ?>
                </label>
                <textarea name="comments" id="comments" cols="45" rows="5"><?php 
                    if (isset($missing)) {
                        echo htmlentities($_POST['comments'], ENT_QUOTES);
                    } ?></textarea>
              </p>
              <p>

              <p class="text">
                Please check the box if you would like to sign up for our Mailing List!
                <input type="checkbox" name="subscribe" value="Yes"
                <?php if (isset($missing)) {
                    echo 'value="'.htmlentities($_POST['subscribe'], ENT_QUOTES).'"';
                    } ?>
                >
              </p>

              <p>
                <?php
                    require_once('recaptchalib.php');
                    $publickey = "6Lf3NdQSAAAAAOAwgPGRybLnY175X6k9PJ1F2vHx"; // you got this from the signup page
                    echo recaptcha_get_html($publickey);
                ?>
              </p>
              <p class="last">
                <input type="submit" name="send" id="send" value="Send Message">
              </p>
            </form>

