Answer the question
In order to leave comments, you need to log in
Why do I get unformatted data when submitting a form?
Hello! I'm interested in the question: why does the data come in unformatted form (in one line) when sending the form to the mail 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 = '[email protected]'; // 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: [email protected] \r\n";
$headers .= "Reply-To: $email";
mail($to, '=?UTF-8?B?'.base64_encode($email_subject).'?=',$email_body,$headers);
return true;
?>
Answer the question
In order to leave comments, you need to log in
Well, format it as HTML, and my advice to you is to unlearn writing variables in double quotes once and for all.
Do not be lazy to concatenate strings
$email_body = '<h4>Заполнена форма</h4>
<div>Задать вопрос</div>
<p>Данные отправителя</p>
<p>Имя: ' . $name . '</p>
<p>Email: ' . $email . '</p>
<p>Вопрос: ' . $message . '</p>';
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question