U
U
uzi_no_uzi2019-09-18 20:00:47
PHP
uzi_no_uzi, 2019-09-18 20:00:47

Krakozyabry come from the feedback form?

I am using this script. Letters come to the mail, but for some reason there are problems with the encoding.
The files are UTF-8 encoded without BOM.
5d8262a8308af827324871.png

<?php
require_once __DIR__.'/vendor/autoload.php';


use PHPMailer\PHPMailer\PHPMailer;

if(strlen($_POST['mail'])>5 and strlen($_POST['ms'])>4 and strlen($_POST['name'])>1 and strlen($_POST['phone'])>4){
error_reporting(E_ALL);
ini_set("display_errors", 1);

    function send_email($to,$theme,$message){   
        $mail = new PHPMailer(true); // Passing `true` enables exceptions
        try {
            //Server settings
            $mail->SMTPDebug = 0; // Enable verbose debug output
            $mail->isSMTP(); // Set mailer to use SMTP
            $mail->Host = 'smtp.mail.ru'; // Specify main and backup SMTP servers
            $mail->SMTPAuth = true; // Enable SMTP authentication
            $mail->Username = '[email protected]'; // SMTP username
            $mail->Password = 'xxxxx'; // SMTP password
            $mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
            $mail->Port = 587; // TCP port to connect to
            $mail->SMTPOptions = array(
                'ssl' => array(
                    'verify_peer' => false,
                    'verify_peer_name' => false,
                    'allow_self_signed' => true
                )
            );  
            //Recipients
            $mail->setFrom('[email protected]', 'Customer');
            $mail->addAddress('[email protected]', 'Putnik-center'); // Add a recipient

            $mail->isHTML(true); // Set email format to HTML
            $mail->Subject = 'Customer order Putnik-center';
            $mail->Body = 'Name: '.$_POST['name'].'<br /> Mail: '.$_POST['mail'].'<br /> Phone: '.$_POST['phone'].'<br /> Message: '.$_POST['ms'];
            $mail->AltBody = 'Application';
            $mail->send();
            echo '+';
        } catch (Exception $e) {
            echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
        }



    }

    if(send_email('','Заказ', 'Имя:'.$_POST['name'].'. <br >Cообщение: '.$_POST['ms'].'. <br> Почта: '.$_POST['mail'])){
        echo "+";
    }
}
?>

Answer the question

In order to leave comments, you need to log in

3 answer(s)
T
ThunderCat, 2019-09-18
@uzi_no_uzi

the mailer does not know what strings you are sending him, specify the encoding, read the doc
$mail->CharSet = 'UTF-8';

A
Alexander Shvedov, 2019-09-18
@constintmid

With the encoding of the problem, therefore, these krakozyabry come

P
postgresdev, 2019-09-18
@postgresdev

specify file encoding
and specify in php:
header('Content-Type: text/html; charset=utf-8');

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question