`

<?php $fio = $_POST['name']; $phone = $_POST['phone']; $fio = htmlspecialchars($fio); $phone = htmlspecialchars($phone); $fio = urldecode($fio); $phone = urldecode($phone); $fio = trim($fio); $phone = trim($phone); $VISIT_TYPES = [ 'standard' => 2000, 'consultation' => 5000 ]; $requested_visit_type = $_POST['visit_type']; if(in_array($requested_visit_type, array_keys($VISIT_TYPES), true)) { header('Location: https://money.yandex.ru/to/410015106353027/' + $VISIT_TYPES[$requested_visit_type]); mail("e-prohorov-2000@yandex.ru", "Заявка с сайта", "Имя: ".$fio.".\n Телефон: ".$phone.".\n Заплатил:" .$VISIT_TYPES[$requested_visit_type] , "From: e-prohorov-2000@yandex.ru \r\n"); } else { echo 'Неподдерживаемый вариант посещения!'; } ?> 

 <html> <form action="mail.php" method="post" id="backmail" style="max-width: 420px; margin:0 auto;"> <p class="text">Выберите вариант посещения:</p> <label> <input class="radio" type="radio" name="visit_type" value="standard"> <span class="radio-custom rtext"></span> <span class="label rtext"><b>2000 руб.</b> - стандартное посещение курса</span> </label> <label> <input class="radio" type="radio" name="visit_type" value="consultation"> <span class="radio-custom"></span> <span class="label rtext" style="position: relative;top: 12px;"><b>5000 руб.</b> - посещение курса + 1 час <br>личной консультации спикера</span> </label> <div class="input"> <input type="text" name="name" id="name" placeholder="Ваше имя*" required><br> <input type="text" name="phone" id="phone" placeholder="Ваш телефон*" required> <button type="submit" class="sendmail">Записаться</button> </div> </form> </html> 

`

    1 answer 1

    In order for this code to work it is necessary that the server itself is configured.

    The mail function you use requires an installed sendmail, postfix, or some other mail server. If you use shared hosting, your hoster may not provide such services or enable them on request (contact your ISP technical support). If you have your own VPS / VDS (there is a password for root), then google articles on setting up servers like "How to set up sending mail using the php function of the mail"

    Alternatively, you can not use the mail function (it comes as part of PHP itself), but use different mailing programs - this is the code (packages) that you can connect to your code and use their mail sending functions. As a rule, mailers have not only modes for working with local mail servers, but also the ability to send via a remote mail server such as yandex or gmail. This is just convenient for those who do not have access to configuring php.ini and / or setting up the server itself.

    Examples of mailers in php: phpmailer or swiftmailer