Back to Home: PHP FormMail Generator I Need Help : Ask Question Without Registration

Can a form send email to a different email address depends on dropdown options?
  • admin March 2011
    It's simple to do that. Here is the example in two steps :
    1) create a normal dropdown field with options, e.g. : Sales, Support, Customer Service
    2) then download the form php files, edit the form.lib.php as the following,  just before the  'PHPFMG_TO' line :



    function get_to(){
        $to = array(
            'Sales' => 'a@sympatico.ca',
            'Support' => 'b@gmail.com',


            'Customer Service' => 'c@hotmail.com',
        );
        $default = 'b@gmail.com';
        return isset( $_POST['field_?'] ) && !empty($to[ $_POST['field_?'] ])  ? $to[ $_POST['field_?'] ]: $default;


      
    }

    define( 'PHPFMG_TO' , get_to() );

    please replace the field_? with the real field name. In my case, I got the field name field_2 from the form.lib.php :


    # --- Array of Form Elements ---
    $GLOBALS['form_mail'] = array();
    $GLOBALS['form_mail']['field_0'] = array( "name" => "field_0", "text" => "Your Name",  "type" => "sender's name", "instruction" => "", "required" => "Required" ) ;
    $GLOBALS['form_mail']['field_1'] = array( "name" => "field_1", "text" => "EMail",  "type" => "sender's email", "instruction" => "", "required" => "Required" ) ;
    $GLOBALS['form_mail']['field_2'] = array( "name" => "field_2", "text" => "Department You Want to Contact",  "type" => "select", "instruction" => "", "required" => "Required" ) ;
    $GLOBALS['form_mail']['field_3'] = array( "name" => "field_3", "text" => "Message",  "type" => "textarea", "instruction" => "", "required" => "Required" ) ;

    See screen shot below:
    image
    Attachments
    dynamic-email-from-dropdown.jpg 136K