hjkhghopjkertteerterterterertertrtoirh
bnmbertsurhetertertertertertertertpdf'tdfg
/
srv
/
www
/
virtual
/
dev1.wccweb.jp.dac4.biz
/
web
/
htdocs
/
sp
/
contact
/
t01
/
Upload FileeE
HOME
<?php /** * /contact/t01/MailForm.class.php * * @author Mitsutoshi Nakamura <mitsutoshi.nakamura.jp@gmail.com> */ class MailForm { private $debug = false; //private $mail = 'dac@dac-inc.co.jp'; private $mail = 'info@wccweb.jp'; private $page; private $sess; public function __construct() { session_start(); $this->sess =& $_SESSION['contact']['t01']['f1']; if ($this->debug) { error_reporting(-1); ini_set('display_errors', 1); $this->mail = 'mitsutoshi.nakamura.jp@gmail.com'; } else { error_reporting(0); ini_set('display_errors', 0); } } public function dispatch() { if (isset($_POST['page']) && $_POST['page']) { $this->page = $_POST['page']; } switch ($this->page) { case 'regist': $this->regist(); break; default: $this->pageForm(); break; } } private function pageForm() { $token = $this->getToken(); $html = file_get_contents('tpl/form.tpl.html'); $this->sess['token'] = array('time' => time(), 'code' => $token); echo str_replace('%token%', $token, $html); } private function getToken($algo = 'sha256') { return hash($algo, uniqid(mt_rand(), true)); } private function checkToken() { $token = isset($_POST['token']) ? $_POST['token'] : null; switch (true) { case !$token: case !isset($this->sess['token']): case $token != $this->sess['token']['code']: case $this->sess['token']['time'] < time() - 60 * 5: return false; default: return true; } } private function regist() { if (!$this->checkToken()) { $this->pageForm(); return false; } unset($this->sess['token']); $this->mail(); $this->pageResult(); } private function mail() { mb_language('Japanese'); mb_internal_encoding('UTF-8'); $this->mailUser(); $this->mailAdmin(); } private function mailUser() { $p = $_POST; $t = array('個人情報の取り扱いに関する同意', 'お問い合わせ種別', 'ブランド', 'お問い合わせ内容', 'お名前', 'お名前(カタカナ)', '電話番号', 'E-mail'); $d[] = '◆送信日時' . "\n" . date("Y/m/d H:i:s"); for ($i = 0; $i <= 7; $i++) { if (!isset($p['f1_i' . $i])) { continue; } switch (true) { default: $d[] = '◆' . $t[$i] . "\n" . $p['f1_i' . $i]; } } $m[] = $p['f1_i7']; // To $m[] = '【送信確認メール】お問い合わせ|ワールド通商株式会社'; // Subject $m[] = ''; // Message $m[] = 'From: ' . $this->mail . "\r\n"; // Additional Headers $m[] = '-f' . $this->mail; // Additional Parameters $m[2] = sprintf(file_get_contents('mail.user.txt'), join("\n\n", $d)); // debug begin //$this->pr($p); //$this->pr($d); //$this->pr($m); //exit; // debug end if (!mb_send_mail($m[0], $m[1], $m[2], $m[3], $m[4])) { exit('メールの送信に失敗しました。'); } } private function mailAdmin() { $p = $_POST; $t = array('個人情報の取り扱いに関する同意', 'お問い合わせ種別', 'ブランド', 'お問い合わせ内容', 'お名前', 'お名前(カタカナ)', '電話番号', 'E-mail'); $d[] = '◆送信日時' . "\n" . date("Y/m/d H:i:s"); $d[] = '◆アクセス元ページ' . "\n" . $p['referrer']; for ($i = 0; $i <= 7; $i++) { if (!isset($p['f1_i' . $i])) { continue; } switch (true) { default: $d[] = '◆' . $t[$i] . "\n" . $p['f1_i' . $i]; } } $m[] = $this->mail; // To $m[] = 'お問い合わせ|ワールド通商株式会社'; // Subject $m[] = ''; // Message $m[] = 'From: ' . $p['f1_i7'] . "\r\n"; // Additional Headers $m[] = '-f' . $p['f1_i7']; // Additional Parameters $m[2] = sprintf(file_get_contents('mail.admin.txt'), join("\n\n", $d)); // debug begin //$this->pr($p); //$this->pr($d); //$this->pr($m); //exit; // debug end if (!mb_send_mail($m[0], $m[1], $m[2], $m[3], $m[4])) { exit('メールの送信に失敗しました。'); } } private function pageResult() { readfile('tpl/result.tpl.html'); } private function pr($data) { echo '<pre>'; print_r($data); echo '</pre>'; } }