とあるセクシーなデータ分析官

を目指す渋谷で働くソーシャルゲーム分析者の卵

CakePHP1.2のEmailコンポーネント使ってみた

symfonyにメール送るsfMailがあるのだからCAKEもあるだろうと思い
ググってみたら案の定同じような方を発見しました。


1.使用するcomponentコピーしてくる
cake/libs/controller/components/email.phpをapp/controllers/components/email.php
にコピーしてくる。
※cake1.2だとlibでなくlibsなので注意


2.tmp以下のcacheを削除


3.コンポーネントの宣言


4.メール部分の実装

$body = "testtesttest";
$this->sendMail($body);

    function sendMail($body)
    {
        $hosturl = 'hugahuga@kayac.com';

        $this->Email->charset = 'utf-8';
        $this->Email->to      = $hosturl;
        $this->Email->from    = $hosturl;
        $this->Email->subject = "【報告書】KK";
        $message = $body;
        $this->Email->_lineLength = 100;

        $this->Email->send($message);
    }


pearのmail.phpと同じぐらい便利!
しかも文字化けしない!!


参考:http://www.cpa-lab.com/tech/070