How to connect the form to send email?

Hello world !) There is a form on the website , how to make it work ?

<form action="1.php" method="post" >
 <div class="row">
 <div class="col-md-6">
 <div class="input-contact">
 <input type="text" name="name">
 <span>your name</span>
</div>
</div>
 <div class="col-md-6">
 <div class="input-contact">
 <input type="text" name="email">
 <span>your email</span>
</div>
</div>

 <div class="col-md-12">
 <div class="textarea-contact">
 <textarea name="message"></textarea>
<span>message</span>
</div>
</div>
 <div class="col-md-12">
 <a href="#" class="btn btn-box">send</a>
</div>
</div>
 </form>


<?php header("Content-type: text/html; charset=utf-8");

 $text = "<b>subject</b>: ".$_POST['subject']."<br>";
 $text .= "<b>name</b>: ".$_POST['name']."<br>" ;
 $text .= "<b>email</b>: ".$_POST['email']."<br>";
 $text .= "<b>message</b>: ".$_POST['message']."<br>";
 $headers .= "MIME-Version: 1.0\r\n";
 $headers .= "Content-Type: text/html; charset=UTF-8\r\n";
 mail('mail@mail.ru', 'email Header', $text, $headers);

?>
March 19th 20 at 08:59
2 answers
March 19th 20 at 09:01
In fact, Valentin has already been answered, here's the complete code.

app/index.php
<!DOCTYPE html>
<html lang="EN">
the <head>
 <meta charset="UTF-8">
<title>Document</title>
 <script src="https://code.jquery.com/jquery-2.2.4.min.js"></script>
</head>
the <body>
 <form action="#" id="form">
 <div class="row">
 <div class="col-md-6">
 <div class="input-contact">
 <input type="text" name="name">
 <span>your name</span>
</div>
</div>
 <div class="col-md-6">
 <div class="input-contact">
 <input type="text" name="email">
 <span>your email</span>
</div>
</div>

 <div class="col-md-12">
 <div class="textarea-contact">
 <textarea name="message"></textarea>
<span>message</span>
</div>
</div>
 <div class="col-md-12">
 <button class="btn btn-box">send</button>
</div>
</div>
</form>


the <script>
 jQuery(document).ready(function($) {
 $("#form").on('submit', function(event) {
event.preventDefault();

$.ajax({
 url: '1.php',
 type: 'POST',
 data: $('#form').serialize(),
 success: function(data) {
alert(data);
}
});
});
});
</script>
</body>
</html>

app/1.php
<?php

$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$subject = 'message Subject';

$to = 'email@site.ru';
$from = 'TITLE <no-reply@site.ru>';

$error = "";

if (isset($_POST['message'])) {

 if (!$email) {
 $error .= "Enter your email";
}

 $headers = "MIME-Version: 1.0\r\n";
 $headers .= "Content-type: text/html; charset=UTF-8\r\n";
 $headers .= "From: ".$"from"."\r\n";
 $headers .= "Reply-To: ".$"from"."\r\n";

 $body = "";

 if ($name) {
 $body .= 'Name: '.$name."<br>";
}
 if ($email) {
 $body .= 'Email: '.$email."<br>";
}
 if ($message) {
 $body .= 'Message: '.$message;
}

 if (!$error) {
 if (mail($to, $subject, $body, $headers)) {
 echo 'OK';
 } else {
 echo 'Unable to send email. Please try again.';
}
 } else {
 echo $error;
}

}
Where what email insert? (don't understand)
$to = 'email@site.ru';
$from = 'no-reply@site.ru';

$error = "";

if (isset($_POST['email'])) {

 if (!$email) {
 $error .= "Enter your email";
 }


and why not html?
app/index.php - Fredy.Murr commented on March 19th 20 at 09:04
@Fredy.Murr,
1) $to = 'email@site.ru'; - to whom sent (currently likely send your mail please specify)
$from = 'no-reply@site.ru'; - (from whom you will receive a letter if sent with work domain it is better to specify no-reply@domain.ru in connection with the policy of the postal service of a letter sent from a website should come with this title, containing the domain from which the message was sent, otherwise most likely in the spam gets)
2) index.html - demetrius25 commented on March 19th 20 at 09:07
@demetrius25, not working( - Fredy.Murr commented on March 19th 20 at 09:10
@Fredy.Murr, what exactly doesn't work?) put to archive your files and throw here a link to Yandex disk, for example. - demetrius25 commented on March 19th 20 at 09:13
@demetrius25, come on Skype let's talk
telmatelma032010 - Fredy.Murr commented on March 19th 20 at 09:16
@demetrius25, ?? - Fredy.Murr commented on March 19th 20 at 09:19
March 19th 20 at 09:03
<form action="1.php" method="post" id="form">
<a href="#" class="btn btn-box" onclick="sendForm()">send</a>


function sendForm(){
event.preventDefault();

$.ajax({
 url: 'form.php',
 type: 'POST',
 data: $('#form').serialize(),
 success: function(response) {
$('#result').html(response);
}
 }); 
}
not working - Fredy.Murr commented on March 19th 20 at 09:06
$subject = "letter from site";
$headers = "Content-Type: text/html; charset=\"utf-8\" \r\n"; 
$headers .= "From: ".$"from"."\r\n"; 
$message = "<div><strong>Name:</strong> ".$message contact_name."</div>";
mail($to, $subject, $message, $headers);
echo "Your message has been sent!";
- Ronny_Ebert commented on March 19th 20 at 09:09
@Ronny_Ebert, you the functions of the event are not handed over like - Lenny.Waelchi commented on March 19th 20 at 09:12

Find more questions by tags HTMLCSSPHP