I make the simplest form in php, but the data is not sent, although everything indicates the success of submit . Tried to make other forms, sometimes a message comes, but the data seems to be not, they are not written to a variable. In general, this form does not work, not to mention empty lines. Help!

  <?php $toWho = "worddoc96hiphop@gmail.com"; $name = $_POST['name']; $second = $_POST['second']; $email = $_POST['email']; $message = $_POST['message']; $mess = "Имя: " . $name . " \nОтчество: " . $second . " \nEmail: " . $email . " \nСообщение: " . $message; if(mail($toWho, "Новое письмо", $mess)) { echo 'Success'; } else echo 'DAMN'; ?> 
 <form method="POST" id="form" action='php/main.php' name="form"> <div class="input-1"> <label for="">Имя:</label> <input type="text" placeholder="Иван" autofocus="autofocus" required="required" name="name" id="name"> </div> <div class="input-1"> <label for="">Отчество:</label> <input type="text" placeholder="Иванович" required="required" name="second" id="second"> </div> <div class="email"> <label for="email">Email:</label> </div> <input type="email" placeholder="example@mail.ru" required="required" name="email" id="email"> <div class="message"> <label for="area">Сообщение:</label> </div> <textarea cols="30" rows="10" placeholder="Введите сообщение..." required="required" name="message" id="message"></textarea> <div class="sbm"> <input type="submit" name="submit" value="Отправить"> </div> </form> 

  • Quote: "data is not sent, although everything indicates the successful implementation." Any error displays when sending? - Streletz
  • No, on the contrary, it displays echo Success. Does the script look right? - Alexey Krasnov
  • In PHP, there is an option such as displaying errors. By default it is disabled. The fact that "Success" displays does not say anything by itself. By the way, all the data from the form fields come to the server. What comes in the form of email (if it comes at all)? - Streletz
  • Nothing comes. Before that I tried to make a script differently, empty fields came and everything - Alexey Krasnov

1 answer 1

Reasons why you can't send mail:

1) Sendmail is not configured on the local server, or smtp

2) mail() function disabled on remote server

If you are using a local server, then you should create a txt file where your letters will be entered, if after the line $message = $_POST['message']; add the code below, in the end you will understand that this form works, only the data is not sent to the email due to the reasons above:

// Save To Database

 $f = fopen("message.txt", "a+"); fwrite($f," \n Сообщение от $toWho. Кому: $email. Имя: $name. Отчество: $second"); fwrite($f,"\n $message "); fwrite($f,"\n ---------------"); fclose($f);