php - Send email according to input select value -


i need make changes existing form adding dropdown menu have 2 inputs , values. purpose send form recipient_one if address 1 selected or recipient_two when address 2 selected. address 1 needs default value when nothing selected.

here added html:

<form method="post" action="./index.php" enctype="multipart/form-data">   <fieldset class="elist">            <legend>select shop:</legend>                   <select name="shop">                              <option name="address-chosen" value="tammsaare" >tammsaare</option>                             <option name="address-chosen" value="Ülemiste"  >Ülemiste</option>                   </select>    </fieldset> </form> 

and php:

    $action = isset($_post['action']) ? $_post['action'] : null;  $page = null; $pages = array('info', 'en'); if( isset($_get['page']) && in_array($_get['page'], $pages) ) {     $page = $_get['page']; }  if( !in_array($page, $pages) ) {     $page = ''; }  $mail_sent = false; if( $action == 'add' ) {      //test if shared client     if (!empty($_server['http_client_ip'])){         $ip = $_server['http_client_ip'];     //is proxy address     }elseif (!empty($_server['http_x_forwarded_for'])){         $ip = $_server['http_x_forwarded_for'];     }else{         $ip = $_server['remote_addr'];     }          $message = '';         $message .= 'name: '.safe($_post['name'])."\r\n";         $message .= 'e-mail: '.safe($_post['email'])."\r\n";         $message .= 'phone: '.safe($_post['telephone'])."\r\n";         $message .= 'mark: '.safe($_post['mark'])."\r\n";         $message .= 'model: '.safe($_post['model'])."\r\n";         $message .= 'shop: '.safe($_post['address-chosen'])."\r\n";         $message .= "wants newsletter: ".$soovib_uudiskirja = isset($_post['newsletter']) ? "yes" : "no";         $message .= "\r\n";         $message .= "\r\n";         $message .= "\r\n";         $message .= 'aeg: '.date('d.m.y h:i')."\r\n";         $message .= 'ip: '.$ip."\r\n";      $mail_data = array(         'to_email' => 'email@mail.com',         'from_email' => 'email@mail.com',         'from_name' => 'stock cars',         'subject' => 'reservation',         'message' => $message,      );     mail_send($mail_data);       $mail_sent = true; }   function safe( $name ) {    return( str_ireplace(array( "%0a", "%0d", "content-type:", "bcc:","to:","cc:" ), "", $name ) ); }   function mail_send($arr) {     if (!isset($arr['to_email'], $arr['from_email'], $arr['subject'], $arr['message'])) {         throw new helperexception('mail(); not parameters provided.');     }      $to            = empty($arr['to_name']) ? $arr['to_email'] : '"' . mb_encode_mimeheader($arr['to_name']) . '" <' . $arr['to_email'] . '>';     $from        = empty($arr['from_name']) ? $arr['from_email'] : '"' . mb_encode_mimeheader($arr['from_name']) . '" <' . $arr['from_email'] . '>';      $headers    = array     (         'mime-version: 1.0',         'content-type: text/plain; charset="utf-8";',         'content-transfer-encoding: 7bit',         'date: ' . date('r', $_server['request_time']),         'message-id: <' . $_server['request_time'] . md5($_server['request_time']) . '@' . $_server['server_name'] . '>',         'from: ' . $from,         'reply-to: ' . $from,         'return-path: ' . $from,         'x-mailer: php v' . phpversion(),         'x-originating-ip: ' . $_server['server_addr'],     );      mail($to, '=?utf-8?b?' . base64_encode($arr['subject']) . '?=', $arr['message'], implode("\n", $headers));}      if (isset($_get['page'])) {}  

so question how reconstruct array?

set email variable based on form value:

//default email 1 $email='email@mail.com'; if(isset($_post['shop']) && $_post['shop']=='Ülemiste') {$email='email2@mail2.com';} $mail_data = array(         'to_email' => $email,         'from_email' => $email,         'from_name' => 'stock cars',         'subject' => 'reservation',         'message' => $message,      ); 

edited per edit - not sure how umlaut effect things though


Comments

Popular posts from this blog

php - Magento - Deleted Base url key -

javascript - Tooltipster plugin not firing jquery function when button or any click even occur -

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -