1

My requirement is to send mail in turkish language in php. Here is my code:

$rst2 = $this->selectQry(TBL_MAILSETTING,"mailTypeId='8' AND langId='1'",'0','0');
$query2= $this->getResultRow($rst2);
$subject2 = $query2['mailSubject'];

$subject2 = iconv_mime_decode($subject2, 2, "utf-8");

$subject2 = mb_convert_encoding($subject2, "utf-8","AUTO");
$subject2 = mb_encode_mimeheader($subject2);

$from1 = $_POST['email'];
$query2['message'] = $query2['mailContaint'];
$query2['message']=str_replace("[name]",$_POST[name],$query2['message']);

$message1 = $query2['message'];

mail(
      $from1
    , $subject2
    , "$message1\r\n"
    ,   "From: $from\n"
      . "MIME-Version: 1.0\n" 
      . "Content-type:text/html;charset=iso-8859-1" . "\r\n" 
      . 'X-Mailer: PHP/' . phpversion ()
);

Here every thing is going well but the problem is the subject is going in encoded form as(Takım as Takım) in "evrimii Tebrik Card Designer Takım" Any body can help will appreciated.

collapsar
  • 17,010
  • 4
  • 35
  • 61
  • 1
    Did you try `utf-8` or `iso-8859-9` instead of `iso-8859-1`? – Bora Aug 06 '13 at 07:17
  • yes i had tried utf-8,iso-8859-9,iso-8859-1,iso-8859-2, but result is same. – Girish Kumar Sinha Aug 06 '13 at 07:20
  • you may check this "mbstring.*" strings in /etc/php.ini and /etc/php.d/mbstring.ini, then restart apache, it may help – VIVEK-MDU Aug 06 '13 at 07:26
  • Mail is going perfectily. Mail content witten in turkish languages is ok but subject line is going in encoded form – Girish Kumar Sinha Aug 06 '13 at 07:28
  • Tried `base64_encode` subject? – Bora Aug 06 '13 at 07:28
  • i have tried base64_decode() as well as html_entitiy_decode() too but result is the same – Girish Kumar Sinha Aug 06 '13 at 07:29
  • you tried this http://www.php.net/manual/en/function.mb-convert-encoding.php – VIVEK-MDU Aug 06 '13 at 07:30
  • Like this? `$subject2 ="=?UTF-8?B?".base64_encode($subject2)."?=\n";` – Bora Aug 06 '13 at 07:31
  • @Bora it is also not working friend – Girish Kumar Sinha Aug 06 '13 at 07:32
  • Hi @Girish http://stackoverflow.com/questions/3522416/php-language-problem read @NullUserException♦ – VIVEK-MDU Aug 06 '13 at 07:34
  • charset=windows-1254\r\n you can try this one – Kuzgun Aug 06 '13 at 07:36
  • @VIVEK-MDU http://stackoverflow.com/editing-help#links – DarkBee Aug 06 '13 at 07:36
  • oh man @DarkBee..thank you for revise my comment... – VIVEK-MDU Aug 06 '13 at 07:39
  • might help: http://stackoverflow.com/questions/16237864/mime-encoded-folded-subject-header-results-in-warning-when-calling-mail – ficuscr Aug 06 '13 at 07:48
  • could it be that your table actually contains "Takı ;m" instead of the correct word? so trying to convert ı to another letter wouldn't work, I wouldn't think. try and save with correct encoding at the start, then you won't have problem reading later. – mavili Aug 06 '13 at 08:05
  • print out `$query2['mailSubject']` and see if that's the case. if so, then that's the problem – mavili Aug 06 '13 at 08:07
  • @everyoneAbove Stop suggesting "try x, y or z". Encodings are not magic. You need to do it right, not guesstimate. – deceze Aug 06 '13 at 08:20
  • 2
    @Girish `ı` is an HTML entity. You are not encoding to HTML anywhere in your code, so your original text contains that entity already. It's misplaced there. Get rid of it at the source. – deceze Aug 06 '13 at 08:21
  • 2
    @Girish Beyond that, all you need to do for *headers*, like the subject line, is to *MIME encode* it, because email headers cannot contain non-ASCII characters. The body can be any encoding you like, but you need to set the correct header that declares what encoding the body is in. That's been well covered in many similar questions. – deceze Aug 06 '13 at 08:23

2 Answers2

0

Just an advice: Don't use the built-in mail function. Use Zend Mail, or phpmailer or PEAR Mail, or any good mail package. The point is: A well developed package has solved major problems, also the problem you have asked (regarding encoding).

But anyway: Your question is down to wrong encoding in subject (this is for utf-8):

mail($to, '=?utf-8?B?'.base64_encode($subject).'?=', $message, $headers);

More on the subject character set encoding here:

http://ncona.com/2011/06/using-utf-8-characters-on-an-e-mail-subject/

dennis
  • 620
  • 8
  • 21
0

As stated in the comments, you might have the encoded character already as ı in the database.

You can use html_entity_decode() (http://de2.php.net/function.html-entity-decode) to reverse the encoding.

Daniel W.
  • 31,164
  • 13
  • 93
  • 151