I have a function in PHP where I process the mail that is the following
function enviarEmailST($email, $nombre, $asunto, $cuerpo){
require_once 'PHPMailer/PHPMailerAutoload.php';
$mail = new PHPMailer();
$mail->isSMTP();
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'tls';// Enable TLS encryption, `ssl` also accepted
$mail->Host = 'mail.correo.com';//Modificar
$mail->Port = 237;//Modificar
$mail->Username = '[email protected]'; //Modificar
$mail->Password = 'password'; //Modificar
$mail->setFrom('[email protected]', 'Empresa - Soporte T$eacute;cnico');//Modificar
$mail->addAddress($email, $nombre);
$mail->Subject = $asunto;
$mail->Body = $cuerpo;
$mail->IsHTML(true);
$mail->smtpConnect([
'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
]
]);
if($mail->send()) {
return true;
} else {
return false;
}
}
Occasionally when I set up what would be the sender I do 'Company - Technical Support' but when the mail is received, it does not consider the accents of the sender.
Meanwhile, I have a form from where I send the email.
<form class="ui form" role="form" action="envio.php" method="POST" accept-charset="utf-8" autocomplete="off">
<div class="ui segment">
<div class="three fields">
<div class="field">
<label>Nombre de Usuario:</label>
<input id="usuario" type="text" name="usuario" value="<?php echo $row['usuario']; ?>">
</div>
<div class="field">
<label>Nombre y Apellido:</label>
<input id="nombre" type="text" name="nombre" value="<?php echo $row['nombre']; ?>" >
</div>
<div class="field">
<label>Correo Electrónico:</label>
<input id="email" type="email" name="email" value="<?php echo $row['correo']; ?>" >
</div>
<div class="field">
<label>Id Usuario:</label>
<input name="id" id="id" type="text" value="<?php echo $id; ?>">
</div>
</div>
<div class="field">
<label>Asunto:</label>
<input id="asunto" type="text" name="asunto">
</div>
<div class="field">
<textarea id="cuerpo" type="textarea" name="cuerpo" rows=15 ></textarea>
</div>
<!--Botones de envío de la información-->
<button type="submit" name="save" class="ui green icon button">
<i class="send icon"></i>
Enviar
</button>
</div>
</form>
It turns out that if I put accents in the SUBJECT, they are also ignored when receiving the email, but if I put accents in what would be the BODY of the email, those IF IT TAKES THEM INTO ACCOUNT
Can someone tell me what is going on?
PS: I WANT TO CLARIFY THAT THE EMAIL IS SENT PERFECTLY... THE PROBLEM IS THE ACCENTS OF THE SENDING USER (I mean ME) AND THE ACCENTS OF THE SUBJECT
I had the same problem and I was able to solve it in the following way: you have to encode the subject so that it takes special characters as accents:
Also using the PHPMailer class we can configure it so that it is sent with UTF-8 character encoding using the " CharSet " parameter:
the easiest and most practical solution is to convert the content to utf8 with the following function: