M
M
Mark Rosenthal2014-10-23 09:50:15
PHP
Mark Rosenthal, 2014-10-23 09:50:15

How to send email with PHP script in UTF-8?

The site has a feedback form, but the letters come in unreadable encoding. What to add so that everything still goes in UTF-8?

<?
if (array_key_exists('messageFE', $_POST)) {
  mail ("[email protected]",
        "Пришел вопрос с ".$_SERVER['HTTP_REFERER'],
        "Имя: ".$_POST['nameFE']."\nEmail: ".$_POST['phoneFE']."\nВопрос: ".$_POST['messageFE']);
  echo $_POST['nameFF'];
}
?>

Answer the question

In order to leave comments, you need to log in

4 answer(s)
C
Cyril, 2014-10-23
@pt1c

The encoding is specified in the headers, there is a great example of sending emails.
for example here:

<?php
function mail_utf8($to, $from_user, $from_email, 
                                             $subject = '(No subject)', $message = '')
   { 
      $from_user = "=?UTF-8?B?".base64_encode($from_user)."?=";
      $subject = "=?UTF-8?B?".base64_encode($subject)."?=";

      $headers = "From: $from_user <$from_email>\r\n". 
               "MIME-Version: 1.0" . "\r\n" . 
               "Content-type: text/html; charset=UTF-8" . "\r\n"; 

     return mail($to, $subject, $message, $headers); 
   }
?>

B
BatteryLow, 2014-10-23
@BatteryLow

It is best to use some library like this for example, and sending for you will be a quick and elementary thing.

R
Rustamka Vorontsov, 2014-10-23
@rmfordev

Check .htaccess AddDefaultCharset UTF-8
And the pages must also be in UTF-8
and the actual header of the letter must contain charset=UTF-8

A
Alexander Kubintsev, 2014-10-23
@akubintsev

https://packagist.org/search/?q=mail

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question