PHP 邮件编码问题

PHP mail encoding issue

我发现 php 邮件发送有问题。我需要用 UTF-8 对邮件进行编码。主题工作正常,但消息已损坏。这是我的代码

    <?php
header('Content-Type: text/html; charset=utf-8'); 
if (isset($_POST['submit'])) {
    $name = $_POST['fname'];
    $mail = $_POST['fmail'];
    $discord = $_POST['fdiscord'];
    $vek = $_POST['fage'];
    $q1 = $_POST['fq1'];
    $q2 = $_POST['fq2'];
    $q3 = $_POST['fq3'];
    $q4 = $_POST['fq4'];
    $q5 = $_POST['fq5'];

    $mailto = "nabor@cloud-mc.cz";
    $headers = 'Content-Type: text/plain; charset=utf-8' . "\r\n";
    $headers .= 'Content-Transfer-Encoding: base64' . "\r\n";
    $headers = "From: ".$mail;
    $mailsub = '=?UTF-8?B?' . base64_encode("Nábor - ".$name) . '?=';
    $mailmsg =  '=?UTF-8?B?' . base64_encode("Odpověď na nábor:" .$name.".\n\n\nDiscord:".$discord.".\n\nVěk:".$vek);

    mail($mailto, $mailsub, $mailmsg, $headers);
    header("Location: done.html?mailsend");
}

?>

这就是邮件的样子

主题 Nábor - Kolombooo 来自 tvkolombooo@gmail.com 信息 T2Rwb3bEm8SPIG5hIG7DoWJvcjpLb2xvbWJvb28uCgoKRGlzY29yZDpLb2xvbWJvb28jMzI1Ny4KClbEm2s6MTU=

问题似乎是您将消息编码为 base64:

改变这个:
base64_encode("Odpověď na nábor:" .$name.".\n\n\nDiscord:".$discord.".\n\nVěk:".$vek);
对此:
"Odpověď na nábor:" .$name.".\n\n\nDiscord:".$discord.".\n\nVěk:".$vek;