0

In the following code I used the following line to add the encoding part:

$mail->exec("set names utf8");

However, the email was not sent correctly.

I have tried the following:

$to = $_POST['email'];
      $subject = "Konfirmo regjistrimin ZEROPULSE Team";
      $body = "<p>Përshendetje $emri, faleminderit per anetaresimin tuaj ne webfaqen <a href='http://www.flamurbeqiraj.com'>www.flamurbeqiraj.com</a>!</p>
      <p>Per te aktivizuar llogarine tuaj, ju lutem <a href='".DIR."administrator/aktivizo.php?x=$id&y=$activasion'>klikoni ketu</a>.</p>
      <p>T'gjitha te mirat, ZP Team.</p>";

      $mail = new Mail();
      $mail->setFrom(SITEEMAIL);
      $mail->addAddress($to);
      $mail->subject($subject);
      $mail->exec("set names utf8");
      $mail->body($body);
      $mail->send();

How can I change the encoding UTF-8 part?

Stephen King
  • 581
  • 5
  • 18
  • 31
Flamur Beqiraj
  • 1,957
  • 2
  • 13
  • 18
  • 1
    `$mail->exec("set names utf8");` - seriously ...? You're confusing mindless copy&paste with actually reading up on how stuff works here. (But you still gotte do that yourself, because you failed to inform us what `Mail` is supposed to be in the first place, because a native PHP class that ain't.) – CBroe Apr 16 '18 at 16:23
  • https://stackoverflow.com/questions/279170/utf-8-all-the-way-through – Sammitch Apr 16 '18 at 18:13

1 Answers1

0

Actually for pdo you have to do utf-8 charset in the connection:

new PDO("mysql:host=$host;dbname=$db;charset=utf8")
  • This is my PDO connection `$db = new PDO("mysql:host=".DBHOST.";dbname=".DBNAME, DBUSER, DBPASS);` so it should be like this?: `$db = new PDO("mysql:host=".DBHOST.";dbname=".DBNAME, DBUSER, DBPASS.";charset=utf8");` – Flamur Beqiraj Apr 16 '18 at 16:24
  • No, like this: `$db = new PDO("mysql:host=".DBHOST.";dbname=".DBNAME.";charset=utf8", DBUSER, DBPASS, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'utf8'"));` – AlienBuster Apr 16 '18 at 16:26
  • same problem, dhe "ë" character is displaying as "ë" :/ – Flamur Beqiraj Apr 16 '18 at 16:32
  • Ah, i see, you need to specify the header in the mail. https://stackoverflow.com/questions/7266935/how-to-send-utf-8-email – AlienBuster Apr 16 '18 at 16:36