説明
cakePHPで1.2から増えたEmailComponentsなのですが、
送信処理にmail()関数を使っているので、
普通に使うと日本語が文字化けしてしまいます。
なので、http://code.nanigac.com/source/view/101
を参考にマルチバイト対応にしてみました。
変更点は2箇所、プロパティの追加とメソッドの上書きのみです。
コードが600行を超えているので、変更点のみ記載します。
使用する時は、コントローラに
var $components = array('Email');
を追加し、送る時に
$this->Email->language = 'Japanese';
$this->Email->encoding = 'UTF-8';
$this->Email->_lineLength = 200; // デフォルトは70文字
$this->Email->to = 'xxx@example.com';
$this->Email->subject = '件名';
$this->Email->replyTo = 'noreply@example.com';
$this->Email->from = 'test account<noreply@example.com>';
$msg = 'テストメール';
$this->Email->send($msg);
のように、languageとencodingを設定してやります。
元ファイルのemail.phpは
の1.2xxxからダウンロードし、解凍した中の
です。
mb_send_mailを使っているので「互換性を高く」
と言うcakePHPの思想とは、ずれるかも知れませんが
日本語が使えないと困るので^^;
コメント

- 2:haseken
- 2007/11/09 00:32
確かにその通りです。
その部分は元のemailコンポーネントでreturnで実装されていて、成否を$resultで判定するよう変更したときに見落としていました。
ご指摘ありがとうございます。
修正しておきます。

- 3:ゲスト
- 2007/12/28 10:09
この書き方でメールを作るとヘッダが以下のようにおかしくなりませんか?
(例:UTF-8エンコード指定した場合)
-----------
Content-Type:
Content-Transfer-Encoding:
Mime-Version:
Content-Type:
Content-Transfer-Encoding:
-----------
あと、Fromに日本語が入った場合の文字化け対応も・・・。
ひょっとして私だけでしょうか?
前へ 1 次へ![]()
コメントする
[block]から[/block]までの範囲はブロック表示されます。
部分的に目立たせたい時や、引用などにお使いください。
[code]から[/code]までの範囲は等幅表示されます。
ソースコードや設定ファイルの記述などにお使いください。

















if (ini_get('safe_mode')) {
$result = @mb_send_mail($this->to, $this->subject, $this->__message, $this->__header);
= @mb_send_mail($this->to, $this->subject, $this->__message, $this->__header, $this->additionalParams);
(ini_get('safe_mode')) {
$result = @mb_send_mail($this->to, $this->subject, $this->__message, $this->__header);
else {
$result = @mb_send_mail($this->to, $this->subject, $this->__message, $this->__header, $this->additionalParams);
}
$result
は
if
}
}
としないといけませんね。