1

i'm trying to send an email with a japanese character with PHPmailer, This is my function :

function sendMail()
{
  mb_language('ja');
  mb_internal_encoding('UTF-8');

  $mail = new PHPMailer();

  $mail->isSMTP();
  $mail->SMTPAuth      = true;
  $mail->Host          = EMAIL_HOST; 
  $mail->Port          = EMAIL_PORT;
  $mail->Username      = EMAIL_USERNAME;
  $mail->Password      = EMAIL_PASSWORD;
  $mail->SMTPKeepAlive = true;
  $mail->Mailer        = 'smtp';
  $mail->CharSet       = 'ISO-2022-JP';
  $mail->Encoding      = "7bit"; 
  $mail->SMTPDebug     = 0;
  $mail->From          = EMAIL_SET_FROM_EMAIL;
  $mail->FromName      = mb_encode_mimeheader(EMAIL_SET_FROM_NAME, "ISO-2022-JP-MS");
  $mail->addAddress($this->to);

  if (!empty($this->replyTo)) {
    $mail->addReplyTo($this->replyTo);
  }

  $mail->isHTML(true);
  $mail->Subject = mb_encode_mimeheader($this->subject, "ISO-2022-JP-MS");
  $mail->Body    = mb_convert_encoding($this->body, "ISO-2022-JP-MS", "UTF-8");

  $isSend = $mail->send();

  if (!$isSend) {
    throw new exception(__METHOD__ . '() ' . $mail->ErrorInfo);
  }
}

In the recipient the email body which have Japanese character sometimes broken like this :

Case 1 : エ %j%" : A

Case 2 : My friends Japanese laptop showing several black diamond character with question mark in it. Its on Gmail,

Case 3 : A question mark appear in some Japanese character.

Can any body show me the correct setting for PHP mailer so it can send a Japanese-character mail without unknown character shown in the recipient ?

2 Answers2

0

The black diamond with the question mark on viewing browser means that it has no glyph for that character. The character may be valid but it cannot be displayed.

In other words, it may be a limitation with the system doing the display and not your program.

You should check your program, though. Open the email in a hex editor and verify that the code is what you expect and matches the encoding you've specified.

Brian White
  • 8,332
  • 2
  • 43
  • 67
  • Try this: http://stackoverflow.com/questions/5498197/need-a-good-hex-editor-for-linux One of the answers even describes how to do it within VIM. – Brian White Apr 11 '15 at 02:14
0

You are encoding stuff yourself, and then PHPMailer will be doing it again. When you set the subject and body, just use raw text in the correct charset, don't encode it yourself. You're also setting 7bit encoding with a charset that will not fit into 7 bits. If your text is already in UTF-8, why not stick with that? UTF-8 processing is generally more reliable than 8-bit charsets.

Synchro
  • 35,538
  • 15
  • 81
  • 104