I make a form of sending a letter to the mail from the site. How to do and what to register in the function so that the letters come to the mail in the form of html?

In addition, even simple text comes in a letter to an abracadabra, this is on mail.ru mail, and on yandex.ru everything is fine.

How to solve the problem?

The code is:

if(!isset($hasError)) { $emailTo = 'mail@mail.ru'; //Сюда введите Ваш email $body = "Вам поступил заказ с сайта Вектор-М на: \nПакет $vid_pack $color_view \n\nПараметры: \n\nШирина:$width мм \n\nДлина:$length мм \n\nТолщина:$thickness мкм \n\nКоличеством: $quantity шт.\nпо цене $price руб/шт. на общую сумму $summa руб. \n\nКонтактные данные: \n\nИмя:$contactname \n\nТелефон:$phone \n\nE-mail:$email \n\nПримечание:\n$message\n "; $headers = 'From: Форма заказа с сайта Вектор-М <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email; mail($emailTo, $subject, $body, $headers); $emailSent = true; } else { exit ("<p>Вы заполнили не все обязательные поля, вернитесь назад и заполните все обязательные поля.<br><input name='back' type='button' value='Вернуться назад' onclick='javascript:self.back();'></p>"); } } 
  • add in your code $ headers. = 'Content-type: text / html; charset = windows-1251 '. "\ r \ n"; - Damon

3 answers 3

Try this:

 $to = 'user@example.com'; $subject = 'Заголовок'; $message = ' <html> <head> <title>Заголовок</title> </head> <body> <p>Привет!</p> </body> </html> '; $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=windows-1251' . "\r\n"; $headers .= 'From: Reminder <Reminder@example.com>' . "\r\n"; mail($to, $subject, $message, $headers); 
  • Thank you very much, everything works fine, and on mail.ru too ..., however, in the mail client the opera in the field is still writing abracadabra anyway - cheh1

In the header of the letter you need to specify that this is text / html, by default it is sent as plain text. And the fact that Abra-Kadabra, too, - in the header of the letter you must explicitly specify the encoding. Googling on mime headers .

     <form method="post" action="formmail.php" enctype="application/x-www-form-urlendoded"> 

    The enctype defines the format of the data to be sent when using the post data transfer method. The default is application / x-www-form-urlendoded