php - send mail using if else -


i have form takes state drop down menu , opens pdf based on state value. want send different email based on value using php. want give them choice of 50+ states since have concerned 3 out of 50 states can hard code email ie. myaaemail@mydomain.com, mybbemail@mydomain.com, , mycc@mydomain.com. want put state name or value on email not priority. here if else statements how add email? sure don’t have mention new php.

} if ($_post['recipient'] == 'aa') {     header("location: aa.pdf"); } else if ($_post['recipient'] == 'bb') {     header("location: bb.pdf");           }else if ($_post['recipient'] == 'cc') {     header("location: cc.pdf");           }else {     echo "error processing form";  }  ?> 

you may define associative array e-mails:

$emails = array(     'aa' => 'email1@mydomain.com',     'bb' => 'email2@mydomain.com',     'cc' => 'email3@mydomain.com',     'dd' => 'email4@mydomain.com',     'ee' => 'email5@mydomain.com',     // . . . ); 

and use as: $mail_address = $emails[$_post['recipient']];.

} if ($_post['recipient'] == 'aa') {     header("location: aa.pdf"); } else if ($_post['recipient'] == 'bb') {     header("location: bb.pdf");           }else if ($_post['recipient'] == 'cc') {     header("location: cc.pdf");           }else {     //mark1     if ( isset($_post['recipient']) ) {         echo "error processing form";      } }  if ( isset($emails[$_post['recipient']]) ) {     $address = $emails[$_post['recipient']];     $subject = 'the mail ' . $_post['recipient'];     $message = "hello, i'm writing mail " . $_post['recipient'];      mail($address, $subject, $message); }   ?> 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -

php - Accessing static methods using newly created $obj or using class Name -