Interested in the question: why when sending a form to the mail come data in an unformatted form (in one line) and how to fix it?

<?php // check if fields passed are empty if(empty($_POST['name']) || empty($_POST['message']) || empty($_POST['email'])) { echo "Не переданы данные!"; return false; } $name = $_POST['name']; $message = $_POST['message']; $email = $_POST['email']; // create email body and send it $to = 'aomeone@some.ru'; // put your email $email_subject = "Вопрос с сайта some.ru"; $email_body = "Заполнена форма \"Задать вопрос\" \n\r". "Данные отправителя\r\nИмя: $name\r\n". "Email: $email \r\n". "Вопрос: $message"; $headers = "Content-type: text/html; charset=utf-8 \r\n"; $headers .= "From: info@some.ru \r\n"; $headers .= "Reply-To: $email"; mail($to, '=?UTF-8?B?'.base64_encode($email_subject).'?=',$email_body,$headers); return true; ?> 
  • Before using HTML, you first need to find out what it is - Ipatyev
  • + Mail injection in all its glory - Ipatiev

1 answer 1

Edit the body of the letter with tags, you send html. and why not encode the subject.

 $name = $_POST['name']; $message = $_POST['message']; $email = $_POST['email']; $to = 'kkorushkin@gmail.com'; // put your email $email_subject = "Вопрос с сайта some.ru"; $email_body = "Заполнена форма \"Задать вопрос\" <br/>". "Данные отправителя<br/>Имя: $name<br/>". "Email: $email <br/>". "Вопрос: $message"; $headers = "Content-type: text/html; charset=utf-8 \r\n"; $headers .= "From: info@some.ru \r\n"; $headers .= "Reply-To: $email"; mail($to,$email_subject,$email_body,$headers); 

enter image description here

  • How is it not? - Ipatiev
  • This does not apply to the main issue, I would simply recommend it. It is not clear why you encode the subject. This instruction: ** '=? UTF-8? B?'. Base64_encode ($ email_subject). '? =' ** is not needed, you have already specified a charset in the headers. - Kirill Korushkin
  • @kff getting into the queue of checks, you should choose the questions in which at least something you know. There is a “skip” button for everyone else. - Ipatiev
  • Edited the answer. If you think the answer is wrong, explain what is wrong. - Kirill Korushkin