Smartyテンプレートメールの使用
$body = self::setMailBody($params, 'MAIL_BODY.tpl'); // 添付ファイルのセット $attach['path'] = $imagDir; $attach['cid'] = $id; $attach['name'] = $id . ".jpg"; $attach['encoding'] = "base64"; $attach['type'] = "image/jpg"; $attachList[] = $attach; sendMail($from, $to, $subject, $body, array('X-Mailer' => 'Test') ,true, $attachList);
/** * メール「タイトル」と「ボディ」のSmarty作成 * * @param string $filename * @return array */ private static function setMailBody($params, $mailTemp) { // Smartyの呼び出し $smarty = new Smarty; // キャシューなし $smarty->caching = false; // テンプレートの格納パスを設定する $smarty->template_dir=TEMPLATES_DIR; $smarty->compile_dir=TEMPLATES_C_DIR; // 渡されたデータをアサインする foreach ($params as $key => $value){ $smarty->assign($key, $value); } // Smarty テンプレート導入 $mailTmpPath = TEMPLATES_DIR . '/'. $mailTemp; $body = ''; $body = $smarty->fetch($mailTmpPath); return $body; }