P
P
pashabomber2014-09-01 14:36:37
PHP
pashabomber, 2014-09-01 14:36:37

Why is the sender displayed as "squiggles" in a letter from a form?

Good afternoon!
There is the following form:

<?php
$usermail = $_POST['email'];
$sendto   = $usermail;
$content  = nl2br($_POST['msg']);
// Формирование заголовка письма
$subject  = "Прайс-лист ООО \"Фирма АИВ\"";
$headers .= "From: Фирма АИВ\r\n";
$headers .= "Reply-To: ". $usermail . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html;charset=utf-8 \r\n";
// Формирование тела письма
$msg  = "<html><body style='font-family:Arial,sans-serif;'>";
$msg .= "<p>Текст письма</p>\r\n";
$msg .= "</body></html>";
// отправка сообщения
if(@mail($sendto, $subject, $msg, $headers)) {
  echo "true";
} else {
  echo "false";
}
?>

The letter comes to the mail normally, the text and subject are displayed correctly. But in the field from whom it is displayed in this form: "Фирма РђР"
Can you tell me what the problem is here? I'm not good at php...

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
Vit, 2014-09-01
@fornit1917

In the yard 2014, use already normal libraries for sending mail, for example swiftmailer.org
But if you really like bicycles, then I can offer my century ago:

<?php
class MyMail
{
    public static function send($to, $fromMail, $fromName, $subject, $message)
    {
        $subject = '=?utf-8?B?'.base64_encode($subject).'?=';
        $header = "From: \"$fromName\" <$fromMail>\n";
        $header .= "Subject: $subject\n";
        $header .= "Mime-Version: 1.0\n";
        $header .= "Content-type: text/html; charset=\"utf-8\"\n";
        $body = "$message";
        @mail( $to, $subject, $body, $header, " -f $fromMail" );        
    }  
}

If you still have problems, then specify which mail client you use

A
Andrey Burov, 2014-09-01
@BuriK666

$headers .= 'From: =?utf-8?B?'.base64_encode('Фирма АИВ')."?=\r\n";

O
Oxoron, 2014-09-01
@Oxoron

The problem is with encodings, as the answers suggest.
Google advises to search here:
php.net/manual/ru/ref.mbstring.php (many letters)
habrahabr.ru/post/158895 (many letters on the case and with examples)
www.itdumka.com.ua/index.php?cmd= shownode&node=23 (very short)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question