There is a form:

<form method="POST" action="<?=$_SERVER['SCRIPT_NAME']?>"> <input type="tel" name="tel" placeholder="Введите номер телефона"> <input type="submit" name="submit" value="Заказать"> </form> 

PHP code:

 if (isset($_POST['submit'])) { $tel = $_POST['tel']; echo $tel; $to = "admin@ukr.net"; $subject = "Заказ обратного звонка с сайта"; $message = $tel; mail($to, $subject, $message, "From: no-reply@alkonarkostop.com.ua\r\n"); echo "TRUE"; } else{ echo "false"; } 

Why is the if condition not working?

  • What is meant by "does not work"? - etki
  • does not work, because the letter is not sent, or even your echo is not shown? Are you testing locally or on the server? What is webserver logs? - Barton
  • It does not work exactly POST - it is empty. On the hosting I do, there is no access to the logs .. - spoilt
  • In the browser console you can see the data left? - etki

2 answers 2

If the letter is not sent, then most likely the problem with setting sendmail.

  • C sendmail everything is fine, it does not work exactly POST - it is empty. - spoilt

POST is empty because the value of "submit" is not passed to the global array. The value from the "tel" input is passed there. And the input named "submit" is the submit button of the form. Need to fix php code on

 if (isset($_POST['tel']))..... 
  • one
    In fact, if the input has both a name and value then it is transmitted, unless of course js-magic is used like form.serialze - u_mulder