Transmit Mail.ver2のカスタマイズ

入力内容によって送信先などを変更するカスタマイズ。
実際にやったのは、返信メールのテンプレートを変更するということですが、参考にしたのは送信先の変更です。あまり変わりはないですが。
参考:http://qiita.com/dounokouno/items/21dcf87f2e43a73be551
実際にやったことは、ほぼこの通りです。
1.input.htmlに普通にラジオボタンを入れる

<dt>ご指定<span class="color_1">※</span></dt>
<dd><input type="radio" name="ご指定" value="文面A" id="radio1" {$checked.ご指定.文面A} {$checked.default} />文面A<br />
	<input type="radio" name="ご指定" value="文面B" id="radio2" {$checked.ご指定.文面B} />文面B</dd>

 
2.config/config.phpに以下追記する

$config['mail_body_a'] = 'config/mail_body1.txt';
$config['mail_body_b'] = 'config/mail_body2.txt';
$config['mail_auto_reply_body_a'] = 'config/mail_auto_reply_body1.txt';
$config['mail_auto_reply_body_b'] = 'config/mail_auto_reply_body2.txt';

メールテンプレートは、configファイルからではなく、lib/transmitmail.phpからの位置を記述することになるので注意。
つまるところ、transmitmail.php内にあるデフォルトの指定に沿ったフォーマットにするということ。
 
3.libディレクトリにexTransmitMail.phpを作成する

<?php
class exTransmitMail extends TransmitMail
{
    public function afterSetTemplateProperty()
    {
        if ($this->page_name === 'finish') {
            switch ($this->post['ご指定']) {
                case '文面A':
                    $this->config['mail_body'] = $this->config['mail_body_a'];
                    $this->config['mail_auto_reply_body'] = $this->config['mail_auto_reply_body_a'];
                    break;
                default:
                    $this->config['mail_body'] = $this->config['mail_body_b'];
                    $this->config['mail_auto_reply_body'] = $this->config['mail_auto_reply_body_b'];
                    break;
            }
        }
    }

switchで振り分けているので、ラジオボタンがふたつ以上あっても問題ない。
今回はcheckedであらかじめ何かの値が入っている状態にしているが、switch defaultで「何も値が入っていない」状態でも問題ない形にすることはできる。
 
3.index.phpを修正する

require_once 'lib/TransmitMail.php';
require_once 'lib/exTransmitMail.php';
$tm = new exTransmitMail('config/config.php');
$tm->run();

以上。