L
L
lesmanora2020-04-21 16:01:56
PHP
lesmanora, 2020-04-21 16:01:56

How to send a return message from a form on the site?

Such a question, you need to send a file to the specified email from the form on the site.
That is, there is a button to receive a brochure, when you click on it, the form is filled out and after the message comes to the user's mail, which he left in the form.

How to do it??????????
First encountered this.

<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    if (isset($_POST['name'])) {$name = $_POST['name'];}
    if (isset($_POST['fam'])) {$fam = $_POST['fam'];}
    if (isset($_POST['phone'])) {$phone = $_POST['phone'];}   
    if (isset($_POST['mail'])) {$mail = $_POST['mail'];}    	 	
    if (isset($_POST['text'])) {$text = $_POST['text'];}

    $to = "[email protected]"; /*Укажите адрес, га который должно приходить письмо*/
  $sendfrom   = "[email protected]"; /*Укажите адрес, с которого будет приходить письмо, можно не настоящий, нужно для формирования заголовка письма*/
    $headers  = "From: " . strip_tags($sendfrom) . "\r\n";
    $headers .= "Reply-To: ". strip_tags($sendfrom) . "\r\n";
    $headers .= "MIME-Version: 1.0\r\n";
    $headers .= "Content-Type: text/html;charset=utf-8 \r\n";
    $subject = "$text";
  $message = "$text<br> 
  <b>Имя:</b> $name <br>
  <b>Фамилия:</b> $fam <br>
  <b>Телефон:</b> $phone <br>
  <b>Почта:</b> $mail <br>
  <b>Комментарий:</b> $text <br>
  ";

  
    $send = mail ($to, $subject, $message, $headers);
    if ($send == 'true')
    {
    echo '<center><p class="success">Спасибо за регистрацию! Мы свяжимся с Вами в течение 30 минут.</p></center>';
    }
    else 
    {
    echo '<center><p class="fail"><b>Ошибка. Сообщение не отправлено!</b></p></center>';
    }
} else {
    http_response_code(403);
    echo "Попробуйте еще раз";
}
?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ilya, 2020-04-21
@rpsv

If you want to fiddle with headers, you can use mail , if you want simpler - PHPMailer: https://stackoverflow.com/questions/12301358/send-... (both options are there)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question