77;20202;0ccatbody - よくきたWiki

Loading ...


/**

 *
 */

require_once "Smarty.class.php";
require_once "Mail/mimeDecode.php";

$source_charset = "EUC-JP";
$mail_charset = "ISO-2022-JP";

class MailSmarty extends Smarty {
  function _constructor() {
    parent::_constructor();


    $this->template_dir = _SYS_DATA_DIR_."mail_templates/";
    $this->compile_dir = _SM_TEMPLATES_C_DIR_."mail/";
    $this->config_dir = _SM_CONFIG_DIR_."mail/";
    $this->cache_dir = _SM_CACHE_DIR_."mail/";

    if ( file_exists( $this->compile_dir) != TRUE) {
      mkdir( $this->compile_dir);
    }
    if ( file_exists( $this->cache_dir) != TRUE) {
      mkdir( $this->cache_dir);
    }
  }

  function mailSmarty() {
    $this->_constructor();
  }

  function send_mail( $templateName) {
    $params['include_bodies'] = true;
    $params['decode_bodies']  = true;
    $params['decode_headers'] = true;
    $mimeDecode = new Mail_mimeDecode( $this->fetch( $templateName));

    $mailStructure = $mimeDecode->decode( $params);

    $mailHeader = "";

    $mailTo = $mailStructure->headers[ "to"];


    $mailFrom = $mailStructure->headers[ "from"]; 

    $mailSubject = $mailStructure->headers[ "subject"];
    $mailSubject = mb_convert_encoding( $mailSubject, $mail_encoding, $source_encoding);
    $mailSubject = mb_encode_mimeheader( $mailSubject);

    unset( $mailStructure->headers[ "to"]);
    unset( $mailStructure->headers[ "subject"]);

    $mailBody = mb_convert_encoding( $mailStructure->body, "ISO-2022-JP", "EUC-JP");
    foreach ( $mailStructure->headers as $name=>$value) {
      $name = ucwords( $name);
      $value = mb_encode_mimeheader( $value);
      $mailHeader .= "$name: $value\n";
    }

    mail( $mailTo, $mailSubject, $mailBody, $mailHeader, "-f$mailFrom");
  }
}

?>

mb_language( "ja");
mb_internal_encoding( $source_encoding);

$ms = new MailSmarty;
$ms->send_mail( "template.tpl");

リロード   新規 編集 凍結 差分 添付 複製 改名   トップ 一覧 検索 最終更新 バックアップ   ヘルプ   最終更新のRSS
最終修正日時: Fri, 11 Aug 2006 18:43:27 JST (3908d)
文字数(HTML): 2065
文字数(Wiki): 2144
人気ブログランキング - よくきた wiki