user = new UserInit(); } // メール送信フォーム function display_index(){ $this->user->db->db_close(); $this->user->display_page("index.html"); } // 仮登録完了画面 function display_complete(){ $this->user->db->db_close(); $this->user->display_page("complete.html"); } // メール登録用送信 function do_send(){ // 入力データチェック $err_msg = $this->check_mail_form($this->user->db); if($err_msg){ $this->user->assign_list['err_msg'] = $err_msg; $this->user->assign_list['email'] = $this->user->req['email']; $this->display_index(); return; } // 仮登録ID取得 for($i = 0;$i < 1000;$i++){ $temp_id = $this->get_temp_id(); if(!$this->exist_temp_id($temp_id)){ break; } } $url = "http://www.keiba02.com/magazine/confirm.php?tid=" . $temp_id; $data = array(); $body = <<< EOD 「Keiba02メールマガジン」への仮登録、誠にありがとうございます。 下記の認証URLにアクセスして本登録を行ってください。 $url このメールに心当たりがない場合は、認証URLをクリックせずに、 メールを削除してください。 認証URLをクリックしなければ、読者登録は完了しません。 ──────────── keiba02(ケイバゼロツー) http://www.keiba02.com/ info@keiba02.com EOD; // 仮ID登録 $table = 'mail_temp'; $hash = array(); $hash['temp_id'] = $temp_id; $hash['email'] = $this->user->req['email']; $hash['status'] = 0; $this->user->db->db_insert($table,$hash); $this->user->db->db_close(); $data['to'] = $this->user->req['email']; $data['subject'] = "「Keiba02メールマガジン」本登録用メール"; $data['body'] = $body; $data['header'] = "From: info@keiba02.com"; $mail = new KeibaMail($data); $mail->send_mail(); // 送信完了ページにリダイレクト header("Location: http://" . $_SERVER['HTTP_HOST'] . "/magazine/complete.php"); exit; } // メール記載URLアクセス function display_confirm(){ $temp_id = $this->user->req['tid']; if(!$temp_id){ $this->user->db->db_close(); header("Location: http://" . $_SERVER['HTTP_HOST'] . "/magazine/"); exit; } // 仮登録情報取得 $temp_vec = $this->get_temp_info($temp_id); $this->user->db->db_close(); if(count($temp_vec) > 0){ $this->user->assign_list['email'] = $temp_vec[0]['email']; $this->user->assign_list['temp_id'] = $temp_id; } $this->user->display_page("confirm.html"); } // 登録完了画面 function display_regist_complete(){ $this->user->db->db_close(); $this->user->display_page("regist_complete.html"); } // 本登録処理 function regist(){ $temp_id = $this->user->req['tid']; if(!$temp_id){ $this->user->db->db_close(); header("Location: http://" . $_SERVER['HTTP_HOST'] . "/magazine/"); exit; } // 仮登録情報取得 $temp_vec = $this->get_temp_info($temp_id); if(count($temp_vec) > 0){ // アドレス登録 $table = "magazine_email"; $hash = array(); $hash['email'] = $temp_vec[0]['email']; $this->user->db->db_insert($table,$hash); // 仮登録情報更新 $table = "mail_temp"; $hash = array(); $hash['status'] = 1; $condition = "WHERE temp_id='" . $this->user->db->db_escape($temp_id) . "'"; $this->user->db->db_update($table,$hash,$condition); } $this->user->db->db_close(); header("Location: http://" . $_SERVER['HTTP_HOST'] . "/magazine/regist_complete.php"); exit; } // 仮登録ID取得 function get_temp_id(){ $str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; $char_len = strlen($str); $temp_id = ""; for($i = 0;$i < 10;$i++){ $pos = rand(0,$char_len); $temp_id .= substr($str,$pos,1); } return $temp_id; } // 仮登録情報取得 function get_temp_info($temp_id){ $sql = "SELECT * FROM mail_temp "; $sql .= "WHERE temp_id='" . $this->user->db->db_escape($temp_id) . "' AND "; $sql .= "status=0"; $temp_vec = $this->user->db->db_select($sql); return $temp_vec; } // temp_idが既に登録されているものかチェック function exist_temp_id($temp_id){ $sql = "SELECT count(*) AS tmep_ct FROM mail_temp "; $sql .= "WHERE temp_id='" . $this->user->db->db_escape($temp_id) . "'"; $temp_vec = $this->user->db->db_select($sql); $tmep_ct = 0; if(count($tmep_vec) > 0){ $temp_ct = $temp_vec[0]['temp_ct']; } if($temp_ct > 0){ return TRUE; } return FALSE; } // フォーム内容チェック function check_mail_form($db){ $err_msg = ""; if(Validate::checkNull($this->user->req['email'])){ $err_msg .= "メールアドレスを入力してください
"; } else{ if(Validate::checkMail($this->user->req['email'])){ $err_msg .= "メールアドレスに誤りがあります
"; } else{ // アドレス登録状況チェック $sql = "SELECT count(*) AS mail_ct FROM magazine_email "; $sql .= "WHERE email='" . $db->db_escape($this->user->req['email']) . "'"; $count_vec = $db->db_select($sql); $mail_ct = $count_vec[0]['mail_ct']; if($mail_ct > 0){ $err_msg .= "既に登録されているメールアドレスです
"; } } } return $err_msg; } } ?>