How to make feedback form is normally sent to the Cyrillic alphabet?

Hello! There is a feedback form. It works correctly, but instead of Cyrillic in the message come characters. Please tell me how to fix it?

<?php

use PHPMailer\PHPMailer\PHPMailer;

require 'phpmailer/src/PHPMailer.php';
require 'phpmailer/src/SMTP.php';

$toemails = array();

$toemails[] = array(
 'email' => 'info@montastroy.ru', // Your Email Address

);

// Form Processing Messages
$message_success = 'Your message has been sent successfully.';

// Add this only if you use reCaptcha with your Contact Forms
$recaptcha_secret = "; // Your reCaptcha Secret

$mail = new PHPMailer();

// If you intend you use SMTP, your SMTP add Code after this Line


if( $_SERVER['REQUEST_METHOD'] == 'POST' ) {
 if( $_POST['template-contactform-email'] != ") {

 $name = isset( $_POST['template-contactform-name'] ) ? $_POST['template-contactform-name'] : ";
 $email = isset( $_POST['template-contactform-email'] ) ? $_POST['template-contactform-email'] : ";
 $phone = isset( $_POST['template-contactform-phone'] ) ? $_POST['template-contactform-phone'] : ";
 $service = isset( $_POST['template-contactform-service'] ) ? $_POST['template-contactform-service'] : ";
 $subject = isset( $_POST['template-contactform-subject'] ) ? $_POST['template-contactform-subject'] : ";
 $message = isset( $_POST['template-contactform-message'] ) ? $_POST['template-contactform-message'] : ";

 $subject = isset($subject) ? $subject : 'New message from the contact form on the website';

 $botcheck = $_POST['template-contactform-botcheck'];

 if( $botcheck == " ) {

 $mail->SetFrom( $email , $name );
 $mail->AddReplyTo( $email , $name );
 foreach( $toemails as $toemail ) {
 $mail->AddAddress( $toemail['email'] , $toemail['name'] );
}
 $mail->Subject = $subject;

 $name = isset($name) ? "Name: $name<br><br>" : ";
 $email = isset($email) ? "Email: $email<br><br>" : ";
 $message = isset($message) ? "Message: $message<br><br>" : ";

 $referrer = $_SERVER['HTTP_REFERER'] ? '<br><br><br>This form was sent from the server: '. $_SERVER['HTTP_REFERER'] : ";

 $body = "$name $email $phone $service $message $referrer";

 // Runs only when the File Field is present in the Contact Form
 if ( isset( $_FILES['template-contactform-file'] ) && $_FILES['template-contactform-file']['error'] == UPLOAD_ERR_OK ) {
$mail->IsHTML(true);
 $mail->List( $_FILES['template-contactform-file']['tmp_name'], $_FILES['template-contactform-file']['name'] );
}

 // Runs only when reCaptcha is present in the Contact Form
 if( isset( $_POST['g-recaptcha-response'] ) ) {
 $recaptcha_response = $_POST['g-recaptcha-response'];
 $response = file_get_contents( "https://www.google.com/recaptcha/api/siteverify?secret=" . $recaptcha_secret . "&response=" . $recaptcha_response );

 $g_response = json_decode( $response );

 if ( $g_response->success !== true ) {
 echo '{ "alert": "error", "message": "Captcha is not Validated! Please Try Again." }';
die;
}
}

 // Uncomment the following Lines of Code if you want to Force reCaptcha Validation

 // if( !isset( $_POST['g-recaptcha-response'] ) ) {
 // echo '{ "alert": "error", "message": "Captcha not Submitted! Please Try Again." }';
 // die;
 // }

 $mail->MsgHTML( $body );
 $sendEmail = $mail->Send();

 if( $sendEmail == true ):
 echo '{ "alert": "success", "message": "' . $message_success . '" }';
else:
 echo '{ "alert": "error", "message": "Error sending email." }';
endif;
 } else {
 echo '{ "alert": "error", "message": "Error sending email." }';
}
 } else {
 echo '{ "Error sending email." }';
}
} else {
 echo '{ "alert": "error", "message": "Error sending email." }';
}

?>
March 12th 20 at 08:09
1 answer
March 12th 20 at 08:11
Solution
$mail->CharSet = 'UTF-8';

before $mail->Send();

Well, or that the charset you are sending the letter. Since the characters are not applied - assuming that it is necessary to put CP1251.
Yes, I'm fine now, thanks! - Jovany.Thompson0 commented on March 12th 20 at 08:14

Find more questions by tags PHP