How to set characterset to UTF-8 that affects the subject of mail function with attachment,
Massive headache i’m getting,
i’m using this to send a french content (subject + body) + attached file.
The characters on teh body are okay and display well accented, but the accented chars on the subject are just a mess.
I’m getting the data via POST (except the attached file, allready has defined path on the server).
$email_from = "$Emp->Email";
$email_subject = $_POST['email_subject_posted'];
$email_message = "Nom: $Emp->Nom<br>";
$email_message .= "Prénom: $Emp->Prenom<br>";
$email_message .= "Tel: $Emp->Mobile<br>";
$email_message .= "Email: $Emp->Email<br><br>";
$email_message .= stripslashes(strip_tags($lettre));
$email_message .= "<br><br>";
$email_message .= "Candidature envoyée avec mon compte Example.<br>";
$email_message .= "http://www.example.org<br>";
$email_message .= "1er Site de l’emploi en Algérie.";
$email_to = "$email_candidature";
$headers = "From: ".$email_from;
$file = fopen($CVfile,'rb');
$data = fread($file,filesize($CVfile));
fclose($file);
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";
$email_message .= "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type:text/html; charset=\"utf-8\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$email_message .= "\n\n";
$data = chunk_split(base64_encode($data));
$email_message .= "--{$mime_boundary}\n" .
"Content-Type: {$CVfile_type};\n" .
" name=\"{$CVfile_name}\"\n" .
//"Content-Disposition: attachment;\n" .
//" filename=\"{$CVfile_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data .= "\n\n" .
"--{$mime_boundary}--\n";
$ok = @mail($email_to, $email_subject, $email_message, $headers);
Any input is too much appreciated.
I had such a problem when my PHP file encoding wasn’t similar to message encoding. Check the encoding of your PHP file.