error utf-8 phpmailler

0

I have the following class for sending emails:

<?php

  class EmailEnviarDao {

    public function __construct() {}

    public function enviaEmail($email)  {

      $enviaFormularioParaNome = $email->getNomeAlvo();
      $enviaFormularioParaEmail = $email->getEmailAlvo();

      $caixaPostalServidorNome = 'Hotplate Prensas';
      $caixaPostalServidorEmail = '[email protected]';
      $caixaPostalServidorSenha = '1234567890';

      $remetenteNome  = $email->getNomeRemete();
      $remetenteEmail = $email->getEmailRemete();
      $mensagem = $email->getDescricao();
      $assunto =  $email->getAssunto();
      $qual =  $email->getQual();

      $mensagemConcatenada = '<!doctype html>
                              <html>
                              <head>
                                <meta charset="UTF-8">
                                <?php header("Content-type: text/html; charset=utf-8");?>
                                <title>'.$caixaPostalServidorNome.'</title>
                              </head>
                              <body>
                                Formulário gerado via website<br/><br/><br/>
                                Nome: '.$remetenteNome.'<br/>
                                E-mail: '.$remetenteEmail.'<br/>
                                Assunto: '.$qual=="" ? $assunto : $qual.'<br/>
                                -------------------------------<br/><br/>
                                Mensagem: '.$mensagem.' 
                              </body>';

      $mail = new PHPMailer();

      $mail->IsSMTP();
      $mail->SMTPAuth  = true;
      $mail->Charset   = 'UTF-8';
      $mail->Host  = 'smtp.'.substr(strstr($caixaPostalServidorEmail, '@'), 1);
      $mail->Port  = '587';
      $mail->Username  = $caixaPostalServidorEmail;
      $mail->Password  = $caixaPostalServidorSenha;
      $mail->From  = $remetenteEmail;
      $mail->FromName  = $remetenteNome;
      $mail->IsHTML(true);
      $mail->Subject  = $assunto == "Outro Assunto" ? $qual : $assunto;
      $mail->Body  = $mensagemConcatenada; 
      $mail->AddAddress($enviaFormularioParaEmail,utf8_decode($enviaFormularioParaNome));

      if($mail->Send()){

          return array("success"=>1,"errors"=>"0K");

      } else {

          return array("success"=>0,"errors"=>"Não conseguimos enviar o e-mail");

      }    
    }   

  }

?>

Everything works fine, minus the accents.

I have tried several alternatives published here in the forum but none worked.

The email is fired. But the accents do not!

I tried to put UTF-8 in htmls and

    
asked by anonymous 30.04.2018 / 19:08

1 answer

1
  

Simply use utf8_decode() in the desired variable;

I believe in your case to be utf8_decode($mensagemConcatenada);

    
30.04.2018 / 19:46