There are 3 forms on the page. The values ​​of the fields, depending on the submitted form, fall into an array ( $form _data ).

 if (isset($_POST['login_button'])){ $subject = " registration "; $form_data = array("name" => "{$_POST['name_call_me']}", "question" => "{$_POST['question']}", "phone" => "{$_POST['phone_call_me']}" ); } elseif (isset($_POST['send_btn_call_me'])){ $subject = " did't find a product you need "; $form_data = array("login" => "{$_POST['login']}", "password" => "{$_POST['password']}" ); } elseif (isset($_POST['contact_sent'])){ $subject = " contact "; $form_data = array("name" =>"{$_POST['contact_name']}", "email" => "{$_POST['contact_email']}", "phone" => "{$_POST['contact_phone']}", "subject" => "{$_POST['contact_subject']}", "massage" => "{$_POST['contact_massage']}" ); }; 

The question is how to implement the feedback function, depending on the form submitted. Like that :

 function sent(принимаемый массив $form_data){ в зависимости от выбора формы отправка письма на почту, используя значения из принятого массива} 
  • What is your problem / difficulty? - Alex
  • the difficulty in writing the function itself for processing one form or another, namely, in taking the function as the necessary parameters. That is, I clicked submitting the 1st form - sent a letter with the desired topic, clicked on the 2nd form - sent the letter already with the 2nd topic, and so on - ddeadlink
  • to begin, function sent($_POST) , and then parse $ _POST and generate the send. for a more detailed answer write the code of your sending letter in the question. - Alex
  • the mail function needs to be stuffed into the funtion sent itself () looks like mail ($ to, $ subject, $ massage); $ massage is taken on the basis of the accepted form, for example, if you poke a login_button form then $ massage = $ form_data ["name"]. $ form_data ["question"]. $ form_data ["phone"]; - ddeadlink
  • added an answer, did you want to do so (if not, specify what is wrong)? - Alex

2 answers 2

 function sent($subject, $form_data){ $to = "нужный email"(если из $_POST, то нужно добавить параметр в функцию) $massage = implode(" ", $form_data); if(mail($to, $subject, $massage)){ echo 'The message was sent'; } else{ echo 'The message not sent'; } } if (isset($_POST['login_button'])){ $subject = " registration "; $form_data = array("name" => "{$_POST['name_call_me']}", "question" => "{$_POST['question']}", "phone" => "{$_POST['phone_call_me']}" ); } elseif (isset($_POST['send_btn_call_me'])){ $subject = " did't find a product you need "; $form_data = array("login" => "{$_POST['login']}", "password" => "{$_POST['password']}" ); } elseif (isset($_POST['contact_sent'])){ $subject = " contact "; $form_data = array("name" =>"{$_POST['contact_name']}", "email" => "{$_POST['contact_email']}", "phone" => "{$_POST['contact_phone']}", "subject" => "{$_POST['contact_subject']}", "massage" => "{$_POST['contact_massage']}" ); }; function sent($subject,$form_data); 

    I wanted something like

     function sent_form( $form_data ) { $to = 'test@gmail.com'; $massage = implode(" ", $form_data); if(isset($_POST['login_button'])){ $selected_form = 'key1'; } elseif (isset($_POST['send_btn_call_me'])){ $selected_form = 'key2'; } elseif (isset($_POST['contact_sent'])){ $selected_form = 'key3'; }; switch($selected_form){ case 'key1': $subject = " registration "; $form_data = array("name" => $_POST['name_call_me'], "question" => $_POST['question'], "phone" => $_POST['phone_call_me'] ); mail($to, $subject, $massage); break; case 'key2': $subject = " did't find a product you need "; $form_data = array("login" => $_POST['login'], "password" => $_POST['password'] ); mail($to, $subject, $massage); break; case 'key3': $subject = " contact "; $form_data = array("name" =>"{$_POST['contact_name']}", "email" => $_POST['contact_email'], "phone" => $_POST['contact_phone'], "subject" => $_POST['contact_subject'], "massage" => $_POST['contact_massage'] ); mail($to, $subject, $massage); break; }} 

    I'm not sure that everything is correct, but how and where to call such a function, so that it would process the necessary form

    • The whole function is reduced to 10 lines from our answer, look at it more attentively. - Alex
    • If this is an example, please post it in the text of the question and do not post as an answer. - Alex