I have the following php script sends an email based on parameters returned:
<?
header('Content-Type: application/json; charset=utf-8');
$headers = "From: Source\r\n";
$headers .= "Content-type: text/html;charset=utf-8\r\n";
$to = $data["t_email"];
$subject = "Hello";
$message = (gather_post("locale") == "fr_CA")?"message français ééààèè": "english message";
mail($to, $subject, $message, $headers);
?>
I've taken parts out that are not relevent. The message will be sent out fine, but the accents will not appear correctly. Everything has been set as utf-8 charset, i don't understand why this isn't working.
You may have to encode the html with utf8_encode(). For example:
$message = utf8_encode("message français ééààèè");
I have had to do this to dynamically import French Word docs, and it works great. Let me know if this solves your problem.
<?php
$to = '[email protected]';
$subject = 'subject';
$message = utf8_encode('message français ééààèè');
$headers = 'From: [email protected]' . "\r\n" .
'Reply-To: [email protected]' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
if(mail($to, $subject, $message, $headers)){
echo 'success!';
}
?>
To resolve your issue you need to add the following line to your send email function:
$headers .= 'Content-type: text/plain; charset=UTF-8' . "\r\n";
Here is the integration of this line with an emailing function:
function send_email($to,$subject,$message,$fromemail) {
$headers = "From: $fromemail" . "\r\n";
$headers .= "Return-Path: $fromemail" . "\r\n";
$headers .= "Errors-To: $fromemail" . "\r\n";
$headers .= 'Content-type: text/plain; charset=UTF-8' . "\r\n";
@mail($to,$subject,$message,$fromemail);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With