I receive email correctly. For safety purpose I've hidden my recaptcha secret key but this part is working fine. When I receive the email the subject's special characters are displayed correctly. However, if french accents are sent in the message (éèàç
, for example) the are displayed like this (éèà ç
). As this is a french website, this is a real problem. I tried utf8_encode($message)
in the mail function but to no avail. I looked at other stackoverflow posts but none helped. Also in the message this part is displayed as Content-type: text/plain; charset=UTF-8'
. Can this be avoided?
<?php
if(isset($_POST['valider'])) {
$url = 'https://www.google.com/recaptcha/api/siteverify';
$privateKey = "secret";
$response = file_get_contents($url."?secret=".$privateKey."&response=".$_POST['g-recaptcha-response']."&remoteip=".$_SERVER['REMOTE_ADDR']);
$data = json_decode($response);
if(isset($data->success) AND $data->success==true){
$rusty = 'email@email.com';
$destinataire = $_POST["email"];
$message = utf8_encode(wordwrap($_POST['message']));
$subject = "Question pour la méthode EtVoilà";
$headers = 'From:' . $destinataire."
";
$header_ = 'MIME-Version: 1.0' . "
" . 'Content-type: text/plain; charset=UTF-8' . "
";
if(mail($rusty,'=?UTF-8?B?'.base64_encode($subject).'?=',$message,$header_ . $headers)) {
header('Location: index.php?MessagePass=True');
} else {
header('Location: index.php?MessageError=True');
}
}
}
?>