K
K
korax666232021-09-02 10:26:27
PHP
korax66623, 2021-09-02 10:26:27

How to create send the data of an existing form on the site to e-mail?

IMPORTANT! The site is written on a local server.
The site has a feedback form block:

html form code:

<div class="modal-content">
                    <span class="close">×</span>
                    <div class="mailform">
                        <form action="./send.php" method="POST">
                          <div class="row">
                            <div class="col-25">
                              <label for="fio">Ф.И.О.</label>
                            </div>
                            <div class="col-75">
                              <input type="text" id="fio" name="fio" placeholder="Ваше имя.." required>
                            </div>
                          </div>
                          <div class="row">
                            <div class="col-25">
                              <label for="email">Email</label>
                            </div>
                            <div class="col-75">
                              <input type="text" id="email" name="email" placeholder="Ваша электронная почта.." required>
                            </div>
                          </div>
                          <div class="row">
                            <div class="col-25">
                              <label for="telephone">Телефон</label>
                            </div>
                            <div class="col-75">
                              <input type="text" id="telephone" name="telephone" placeholder="Ваш контактный телефон.." required>
                            </div>
                          </div>
                          <div class="row">
                            <div class="col-25">
                              <label for="city">Город</label>
                            </div>
                            <div class="col-75">
                              <input type="text" id="city" name="city" placeholder="Откуда вы?..">
                            </div>
                          </div>
                          <div class="row">
                            <div class="col-25">
                              <label for="subject">Сообщение</label>
                            </div>
                            <div class="col-75">
                              <textarea id="subject" name="subject" placeholder="Напишите здесь Ваш запрос или сообщение.." style="height:200px" required></textarea>
                            </div>
                          </div>
                          <div class="row">
                            <input type="submit" value="Отправить">
                          </div>
                        </form>
                      </div>
                </div>



Using instructions from the internets, I created a send.php file
This is what its insides look like:

<?php
$fio = $_POST['fio'];
$email = $_POST['email'];
$telephone = $_POST['telephone'];
$city = $_POST['city'];
$subject = $_POST['subject'];

$fio = htmlspecialchars($fio);
$email = htmlspecialchars($email);
$telephone = htmlspecialchars($telephone);
$city = htmlspecialchars($city);
$subject = htmlspecialchars($subject);

$fio = urldecode($fio);
$email = urldecode($email);
$telephone = urldecode($telephone);
$city = urldecode($city);
$subject = urldecode($subject);

$fio = trim($fio);
$email = trim($email);
$telephone = trim($telephone);
$city = trim($city);
$subject = trim($subject);

echo $fio;
echo "<br>";
echo $email;

mail("[email protected]", "Заявка с сайта", "Отправитель: ".$fio". Email: ".$email". Телефон: ".$telephone". Город: ".$city". Сообщение: ".$subject,"From: [email protected] \r\n");

if mail("[email protected]", "Заявка с сайта", "Отправитель: ".$fio". Email: ".$email". Телефон: ".$telephone". Город: ".$city". Сообщение: ".$subject,"From: [email protected] \r\n"))
    {
        echo "Сообщение успешно отправлено";
    } else {
        echo "Ошибка при отправке сообщения";
    }
}?>



Unfortunately, I do not have the opportunity to test the whole thing on the current hosting. But when I click on the "Submit" button, it throws me into a file with the above php code. I'm not familiar with the syntax. Is it possible to check my code and give a hint to a newbie if I made a mistake?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question