Skip to content
Advertisement

PHP mail encoding issue

i found an issue with php mail sending. I need to encode the mail in UTF-8. The subject works fine, but the message is corrupted. This is my code

    <?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' . "rn";
    $headers .= 'Content-Transfer-Encoding: base64' . "rn";
    $headers = "From: ".$mail;
    $mailsub = '=?UTF-8?B?' . base64_encode("Nábor - ".$name) . '?=';
    $mailmsg =  '=?UTF-8?B?' . base64_encode("Odpověď na nábor:" .$name.".nnnDiscord:".$discord.".nnVěk:".$vek);

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

?>

And this is how the mail looks like

Subject Nábor – Kolombooo From tvkolombooo@gmail.com Message T2Rwb3bEm8SPIG5hIG7DoWJvcjpLb2xvbWJvb28uCgoKRGlzY29yZDpLb2xvbWJvb28jMzI1Ny4KClbEm2s6MTU=

Advertisement

Answer

The problem seems to be that you are encoding your message as base64:

Change this:
base64_encode("Odpověď na nábor:" .$name.".nnnDiscord:".$discord.".nnVěk:".$vek);
To this:
"Odpověď na nábor:" .$name.".nnnDiscord:".$discord.".nnVěk:".$vek;

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement