elgg 1.7.8ですが、日本語環境ではメールは全てUTF-8になってしまうのでしょうか

51 views
Skip to first unread message

yo0810

unread,
May 3, 2011, 4:40:19 AM5/3/11
to Elgg 日本ユーザーグループ
elgg 1.7.8ですが、日本語環境ではelggから送られるメールは全てUTF-8になってしまうのでしょうか

メーラによってはUTF-8には対応していない為、文字べ家の原因となってしまいます。

皆様はどのような対応をされていますでしょうか。

よろしくお願いします。

Takeshi Fujisawa

unread,
May 3, 2011, 5:49:19 AM5/3/11
to elgg-...@googlegroups.com
気にしていませんでしたが、以下のファイルに UTF-8決め打ちでした。。

./engine/lib/notification.php

この中の elgg_send_email という関数を修正すればJISで送れるようになると思います。


2011年5月3日17:40 yo0810 <yo0...@gmail.com>:

--
藤澤 武 <takeshi....@gmail.com>
http://chnops.jp/

yo0810

unread,
May 3, 2011, 6:27:49 AM5/3/11
to Elgg 日本ユーザーグループ
とても早い回答ありがとうございます。

ソースを見てみました。ユーザ登録時に言語選択を行い、その言語に合わせたメールを送れると
ベストなんでしょうね。

修正してみます。

ありがとうございました。

ひいろ

unread,
Jun 8, 2011, 7:00:52 AM6/8/11
to Elgg 日本ユーザーグループ
私はどうせISO-2022-JPしか使用しないので、以下のように修正してしまいました。
/**** 追加 ****/ とか /**** 削除 **** とか書いてある箇所が、変更部分です。

elgg-1.7.4なので多少異なるかも知れません。
ご参考までに。


//////////////////////
function elgg_send_email($from, $to, $subject, $body, array $params =
NULL) {
global $CONFIG;

/**** 追加 ****/
mb_language('ja');
/**************/

if (!$from) {
throw new
NotificationException(sprintf(elgg_echo('NotificationException:NoEmailAddress'),
'from'));
}

if (!$to) {
throw new
NotificationException(sprintf(elgg_echo('NotificationException:NoEmailAddress'),
'to'));
}

// return TRUE/FALSE to stop elgg_send_email() from sending
$mail_params = array( 'to' => $to,
'from' =>
$from,
'subject' =>
$subject,
'body' =>
$body,
'params' =>
$params);
$result = trigger_plugin_hook('email', 'system', $mail_params,
NULL);
if ($result !== NULL) {
return $result;
}

$header_eol = "\r\n";
if (isset($CONFIG->broken_mta) && $CONFIG->broken_mta) {
// Allow non-RFC 2822 mail headers to support some
broken MTAs
$header_eol = "\n";

}

// Windows is somewhat broken, so we use just address for to
and from
if (strtolower(substr(PHP_OS, 0 , 3)) == 'win') {
// strip name from to and from
if (strpos($to, '<')) {
preg_match('/<(.*)>/', $to, $matches);
$to = $matches[1];
}
if (strpos($from, '<')) {
preg_match('/<(.*)>/', $from, $matches);
$from = $matches[1];
}
}
/**** 削除 ****
$headers = "From: $from{$header_eol}"
. "Content-Type: text/plain; charset=UTF-8;
format=flowed{$header_eol}"
. "MIME-Version: 1.0{$header_eol}"
. "Content-Transfer-Encoding: 8bit{$header_eol}";
**************/

/**** 追加 ****/
$headers = "From: $from{$header_eol}"
. "Content-Type: text/plain; charset=ISO-2022-JP";
/**************/

// Sanitise subject by stripping line endings
$subject = preg_replace("/(\r\n|\r|\n)/", " ", $subject);

/**** 削除 ****
if (is_callable('mb_encode_mimeheader')) {
$subject = mb_encode_mimeheader($subject,"UTF-8",
"B");
}
**************/

// Format message
$body = html_entity_decode($body, ENT_COMPAT, 'UTF-8'); //
Decode any html entities
$body = strip_tags($body); // Strip tags from message
$body = preg_replace("/(\r\n|\r)/", "\n", $body); // Convert
to unix line endings in body
$body = preg_replace("/^From/", ">From", $body); // Change
lines starting with From to >From

/**** 削除 ****
return mail($to, $subject, wordwrap($body), $headers);
**************/

/**** 追加 ****/
return mb_send_mail($to, $subject, $body, $headers);
/**************/
}


Reply all
Reply to author
Forward
0 new messages