Situation
I have an email newsletter system, emails are sent to clients every day, but I noticed that when using accents such as ´~'^
, the words unconfigured like this: ÓAÃÃÃ
below.
Well, I've tried to include <meta charset="UTF-8">
and other encodings, but nothing changes, as well as saving with UTF-8 encoding.
Important Information
The subject also has the same problem, ie the entire email, from subject to message leave with unconfigured accents.
The code php
looks like this:
<?php
$msg_para = $_POST["msg_para"];
$msg_assunto = $_POST["msg_assunto"];
$msg_tipo = $_POST["msg_tipo"];
$mensagem = $_POST["mensagem"];
if($msg_para == "todos"){
$sql = mysql_query("SELECT * FROM list-emails WHERE ativo = 'online'");
$total = mysql_num_rows($sql);
$mailok = 0;
$falha = 0;
while($lista = mysql_fetch_array($sql)){
$email = $lista["email"];
$cabecalho = "From: $a_nome <$a_email>";
$cabecalho .= "\nReply-To: $a_nome <$a_email>";
$cabecalho .= "\nContent-Type: $msg_tipo";
if(@mail($email,$msg_assunto,$mensagem,$cabecalho)){
$mailok = $mailok + 1;
$msg = "<font color=green>SUCESSO!</font>";
}
else{
$falha = $falha + 1;
$msg = "<font color=red>FALHA!</font>";
}
?>
<font face="Arial" size="2">Enviando para <b><?=$email?></b>...
<b><?=$msg?></b></font><br>
<?php } ?>
<script>alert("<?=$total?> e-mails deveriam ser enviados...\n<?=$mailok?>
foram mandados corretamente,\n<?=$falha?> falharam!\n") </script>
<?php
}
else{
$cabecalho = "From: $a_nome <$a_email>";
$cabecalho .= "\nReply-To: $a_nome <$a_email>";
$cabecalho .= "\nContent-Type: $msg_tipo";
if(@mail($msg_para,$msg_assunto,$mensagem,$cabecalho)){
$msg = "<font color=green>SUCESSO!</font>";
}
else{
$msg = "<font color=red>FALHA!</font>";
}
?>
<font face="Arial" size="2">Enviando para <b><?=$msg_para?></b>...
<b><?=$msg?></b></font><br><?php
}
}
else{
echo "<script>location.href='login.php'</script>";
}
?>
The full code can be checked here
Briefly I need somehow to put UTF-8 encoding or any other that does not have issues with accentuations in email.
@Edit 04/14/16 08:23 AM
One thing I noticed is that the name of the email set in config.php
comes out with normal accents, the only fields that have this problem are the subject and the message . The code for config.php
looks like this:
<?php
$host = "4322-8922";
$usuario = "5";
$senha = "4";
$banco = "321";
mysql_connect($host,$usuario,$senha);
mysql_select_db($banco);
$a_nome = "Téstê dê Ácëñtõs StáckÔvèrFlôw";
$a_email = "[email protected]";
$formato_msg = "Text/HTML";
$confirm_assunto = "Confirmação de Email $a_nome"; //esse assunto é especificamente para a parte de newsletter
$titulo = "Máîs Úm Tèstê";
$url = "http://pt.stackoverflow.com";
$url_sist = "http://pt.stackoverflow.com";
?>
And the result of the email is like this:
Using text converters is out of the question since sending the email is done directly by the system, this would cause a slowness in the process.