Jump to content

[SOLVED] Submit Sends to Specific Email Depending on Drop Down List Selection


Recommended Posts

I'm brand new to php.  I have a contact form with text fields for user info, a working array menu, and a submit button.

 

In my 2nd php file with all the commands in it, it is currently set up to send the user info to an email address.  It works fine.

 

But how do I change it to send the info to a ONE of a list of email address depending on WHICH MENU ITEM IS SELECTED.

 

Thanks!

 

 

 

I am assuming that you want to send an e-mail to specific groups of people.

 

$list1 = array(..);//list of e-mail addresses
$list2 = array(..);

define('EMAIL_LIST_SUBSCRIBERS', 'subscribers');
define('EMAIL_LIST_MANUFACTURERS', 'manufacturers');

$final_list = array();
if ('POST' === $_SERVER['REQUEST_METHOD']) {
    if (!empty($_POST['list'])) {
        switch ($_POST['list']) {
            case EMAIL_LIST_SUBSCRIBERS:
                $final_list = $list1;
                break;
            case EMAIL_LIST_MANUFACTURERS:
                $final_list = $list2;
                break;
        }
        
        if (!empty($final_list)) {
            foreach ($final_list as $email_address) {
                mail($email_address, ..);
            }
        }
    }
}

Actually, I want to email the info to only one recipient (from a few different possibilities).  Which recipient gets the email would depend on the drop down menu selection in the form.

 

Do you have sample code for doing this?

$email_addresses = array(..);

if (!empty($_POST['mail_to']) {
    $mail_to = (int) $_POST['mail_to'];
    if (isset($email_addresses[$mail_to])) {
        $email_address = $email_addresses[$mail_to];
        mail($email_address, ..);
    }
}
else {
    foreach ($email_addresses as $key => $email_address) {
        echo '<option value="', $key, '">', substr($email_address, 0, $pos = strpos($email_address, '@') ? $pos : null), '</option>';
    }
}

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.