-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontact-form.php
333 lines (280 loc) · 11.7 KB
/
contact-form.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
<?php
#下3段式抓 為案件編號 $case_code
#$case_code_test 是用來判斷是否為1的測試頁
#$case_code = "jw";特殊案使用
$src =$_SERVER['SERVER_NAME'];
$case_code_test = substr(substr($src,0,strpos($src,'.')),-1);
$case_code = "cang-m";
# PDO DB 連線 Start
$pdo=new pdo('mysql:host=localhost;dbname=unigiant_htw','unigiant_htw','unigiant_htw');
$pdo->exec("SET NAMES 'utf8'");
# PDO DB 連線 End
# 下3段 抓$case_name 這樣就不會打錯案名了
# $case_name = "鳳翔"; 特殊案使用
$sql_name = "SELECT casename FROM susers WHERE email = '" . $case_code . "'";
$dataList = $pdo->query($sql_name)->fetchAll();
$case_name = $dataList[0]['casename'];
$name = isset($_POST['name']) ? $_POST['name'] : '';
$phone = isset($_POST['phone']) ? $_POST['phone'] : '';
$user_email = isset($_POST['email']) ? $_POST['email'] : '';
$city = isset($_POST['city']) ? $_POST['city'] : '';
$area = isset($_POST['area']) ? $_POST['area'] : '';
$gender = isset($_POST['gender']) ? $_POST['gender'] : '';
$infosource = isset($_POST['infosource']) ? $_POST['infosource'] : '';
$parking = isset($_POST['parking']) ? $_POST['parking'] : '';
$houseStyle = isset($_POST['houseStyle']) ? $_POST['houseStyle'] : '';
$room = isset($_POST['room']) ? $_POST['room'] : '';
$contacttime = isset($_POST['contacttime']) ? $_POST['contacttime'] : '';
$msg = isset($_POST['msg']) ? $_POST['msg'] : '';
$utm_source = isset($_POST['utm_source']) ? $_POST['utm_source'] : '';
$utm_medium = isset($_POST['utm_medium']) ? $_POST['utm_medium'] : '';
$utm_content = isset($_POST['utm_content']) ? $_POST['utm_content'] : '';
$utm_campaign = isset($_POST['utm_campaign']) ? $_POST['utm_campaign'] : '';
$datetime = date ("Y-m-d H:i:s" , mktime(date('H'), date('i'), date('s'), date('m'), date('d'), date('Y'))) ;
# 鳳翔 fs 客製資料:房型
$house = isset($_POST['house']) ? $_POST['house'] : '';
# 好站 hj 客製資料:可聯絡時間
$time_start = isset($_POST['time_start']) ? $_POST['time_start'] : '';
$time_end = isset($_POST['time_end']) ? $_POST['time_end'] : '';
# 不同版本前端相容 Start
if ($name == '') {
$name = isset($_POST['widget-contact-form-name']) ? $_POST['widget-contact-form-name'] : '';
}
if ($phone == '') {
$phone = isset($_POST['widget-contact-form-phone']) ? $_POST['widget-contact-form-phone'] : '';
}
if ($user_email == '') {
$user_email = isset($_POST['widget-contact-form-email']) ? $_POST['widget-contact-form-email'] : '';
}
if ($city == '') {
$city = isset($_POST['widget-contact-form-city']) ? $_POST['widget-contact-form-city'] : '';
}
if ($area == '') {
$area = isset($_POST['widget-contact-form-area']) ? $_POST['widget-contact-form-area'] : '';
}
if ($msg == '') {
$msg = isset($_POST['widget-contact-form-msg']) ? $_POST['widget-contact-form-msg'] : '';
}
if ($utm_source == '') {
$utm_source = isset($_POST['widget-contact-form-utm_source']) ? $_POST['widget-contact-form-utm_source'] : '';
}
if ($utm_source == '') {
$utm_source = isset($_POST['widget-contact-form-utm_source']) ? $_POST['widget-contact-form-utm_source'] : '';
}
if ($utm_medium == '') {
$utm_medium = isset($_POST['widget-contact-form-utm_medium']) ? $_POST['widget-contact-form-utm_medium'] : '';
}
if ($utm_content == '') {
$utm_content = isset($_POST['widget-contact-form-utm_content']) ? $_POST['widget-contact-form-utm_content'] : '';
}
if ($utm_campaign == '') {
$utm_campaign = isset($_POST['widget-contact-form-utm_campaign']) ? $_POST['widget-contact-form-utm_campaign'] : '';
}
$datetime = date ("Y-m-d H:i:s" , mktime(date('H'), date('i'), date('s'), date('m'), date('d'), date('Y'))) ;
# 不同版本前端相容 End
$bCheck = true; //信件檢查
# 取得 IP Start
if (!empty($_SERVER["HTTP_CLIENT_IP"])){
$sIp = $_SERVER["HTTP_CLIENT_IP"];
} else if (!empty($_SERVER["HTTP_X_FORWARDED_FOR"])){
$sIp = $_SERVER["HTTP_X_FORWARDED_FOR"];
} else {
$sIp = $_SERVER["REMOTE_ADDR"];
}
# 取得 IP End
# 檢查是否時間範圍內重複留言 Start
$sCheckMsg = ''; //檢查留言內容
if ($msg == '') {
$msg = '無留言';
}
if ((isset($_COOKIE['msg'])) && ($_COOKIE['msg'] != null)) {
$sCheckMsg = $_COOKIE['msg'];
}
setcookie ("msg", $msg, time()+36400);
if (($sCheckMsg === $msg)) { //要三個等號, 不然 null 會等於 empty
$bCheck = false;
}
# 檢查是否時間範圍內重複留言 End
# 檢查所有關鍵字 Start
$sql = "SELECT * FROM `block_message`";
$aGetDbList = $pdo->query($sql)->fetchAll();
$aFilterKeyWordList = array(); //留言關鍵字檢查初始化
$aFilterNameList = array(); //檢查姓名初始化
$aFilterEmailList = array();
$aFilterPhoneList = array();
$aFilterIpList = array();
foreach ($aGetDbList as $sKey => $aGetDb) {
switch ($aGetDb['type']) { //switch Start
case '1': //留言內容
$aFilterKeyWordList[] = $aGetDb['content'];
break;
case '2': //用戶名稱
$aFilterNameList[] = $aGetDb['content'];
break;
case '3': //信箱
$aFilterEmailList[] = $aGetDb['content'];
break;
case '4':
$aFilterPhoneList[] = $aGetDb['content'];
break;
case '5':
$aFilterIpList[] = $aGetDb['content'];
break;
default:
# code...
break;
} //swutch End
}
# 檢查所有關鍵字 End
# 檢查留言關鍵字 Start
// $aFilterKeyWordList = array('game', 'casino', '測試', 'test');
$checkConunt = 0;
foreach ($aFilterKeyWordList as $key => $sFilterKeyWord) {
$checkConunt = explode($sFilterKeyWord, $msg);
if (count($checkConunt) > 1) {
$bCheck = false;
}
}
# 檢查留言關鍵字 End
# 檢查姓名 Start
// $aFilterNameList = array('蔡銘聰');
$checkConunt = 0;
foreach ($aFilterNameList as $key => $sFilterName) {
$checkConunt = explode($sFilterName, $name);
if (count($checkConunt) > 1) {
$bCheck = false;
}
}
# 檢查姓名 End
# 檢查信箱 Start
$checkConunt = 0;
foreach ($aFilterEmailList as $key => $aFilterValue) {
$checkConunt = explode($aFilterValue, $user_email);
if (count($checkConunt) > 1) {
$bCheck = false;
}
}
# 檢查信箱 End
# 檢查電話 Start
$checkConunt = 0;
foreach ($aFilterPhoneList as $key => $aFilterValue) {
$checkConunt = explode($aFilterValue, $phone);
if (count($checkConunt) > 1) {
$bCheck = false;
}
}
# 檢查電話 End
# 檢查IP Start
$checkConunt = 0;
foreach ($aFilterIpList as $key => $aFilterValue) {
$checkConunt = explode($aFilterValue, $sIp);
if (count($checkConunt) > 1) {
$bCheck = false;
}
}
# 檢查IP End
# 取得信箱帳號密碼, Insert google API token Start
$sql = "SELECT * FROM `mail_token` limit 0,1";
$aGetMailTokenDbList = $pdo->query($sql)->fetchAll();
$token = $aGetMailTokenDbList[0]['token'];
$mailName = $aGetMailTokenDbList[0]['mail'];
$mailPwd = $aGetMailTokenDbList[0]['pwd'];
# 取得信箱帳號密碼, Insert google API token End
# 老版本讀取 Start
$db_host = 'localhost';
$db_user = 'unigiant_htw';
$db_pass = 'unigiant_htw';
$db_name = 'unigiant_htw';
$con = mysqli_connect($db_host, $db_user, $db_pass, $db_name);
// mysqli_query("SET NAMES UTF8");
// mysqli_select_db($db_name, $con);
$query = "SELECT tomail FROM susers WHERE email = '".$case_code."'";
$result = mysqli_query($con, $query);
$row = mysqli_fetch_row($result);
if (mysqli_num_rows($result))
{
$tomail = $row[0];
}
$query_admin = "SELECT admin_email FROM admin WHERE email = 'admin'";
$result_admin = mysqli_query($con, $query_admin);
$row_admin = mysqli_fetch_row($result_admin);
if (mysqli_num_rows($result_admin))
{
$tomail_admin = $row_admin[0];
}
# 老版本讀取 End
ini_set("display_errors", "On");
date_default_timezone_set("Asia/Taipei");
require_once('php-mailer/PHPMailerAutoload.php'); //引入phpMailer 記得將路徑換成您自己的path
$mail= new PHPMailer(); //建立新物件
$mail->IsSMTP(); //設定使用SMTP方式寄信
$mail->SMTPAuth = true; //設定SMTP需要驗證
$mail->SMTPAutoTLS = false;
$mail->Host = "cp39.g-dns.com"; //設定SMTP主機
$mail->Port = 25; //設定SMTP埠位,預設為25埠。
$mail->CharSet = "utf-8"; //設定郵件編碼
$mail->Username = $mailName; //設定驗證帳號
$mail->Password = $mailPwd; //設定驗證密碼
$mail->From = "[email protected]"; //設定寄件者信箱
$mail->FromName = $case_name." - 官網網站"; //設定寄件者姓名
$mail->Subject = $case_name." - 官網網站"; //設定郵件標題
$mail->Body = "網站:https://" . $src . "/<BR>姓名:".$name."<BR>手機:".$phone."<BR>居住城市:".$city."<BR>居住地區:".$area."<BR>需求房型:".$room."<BR>留言:".$msg."<BR>備註:"."<BR><BR>填表日期:".$datetime."<BR>廣告來源:".$utm_source."<BR>廣告媒介:".$utm_medium."<BR>廣告名稱:".$utm_campaign."<BR>廣告內容:".$utm_content; //設定郵件內容
$mail->IsHTML(true); //設定郵件內容為HTML
$tomail_arr = explode(",",$tomail);
$mail->IsHTML(true); //設定郵件內容為HTML
$tomail_arr = explode(",",$tomail);
$tomail_admin_arr = explode(",",$tomail_admin);
//檢查沒問題才寄出信件
$bCheck=true;
if ($bCheck == true) { //if start
// var_dump($_SERVER['HTTP_HOST']); exit;
# 添加到 Googlde 資料DB Start
try {
$url = "http://".$_SERVER['HTTP_HOST']."/send.php";
$url .= "?token=".urlencode($token);
$url .= "&name=".urlencode($name);
$url .= "&phone=".urlencode($phone);
$url .= "&email=".urlencode($user_email);
$url .= "&city=".urlencode($city);
$url .= "&area=".urlencode($area);
$url .= "&message=".urlencode($msg);
$url .= "&utm_source=".urlencode($utm_source);
$url .= "&utm_medium=".urlencode($utm_medium);
$url .= "&utm_content=".urlencode($utm_content);
$url .= "&utm_campaign=".urlencode($utm_campaign);
$url .= "&case_code=".urlencode($case_code);
$url .= "&reservation_datetime=".urlencode($datetime);
$html=file_get_contents($url);
// echo "send ok";
} catch (Exception $e) {
// echo "send fail";
}
# 添加到 Googlde 資料DB End
foreach($tomail_arr as $email)
{
$mail->AddAddress("$email");
}
foreach($tomail_admin_arr as $email_admin)
{
$mail->AddBCC("$email_admin");
}
if (!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
// exit;
} else {
echo "Message sent!";
// exit;
}
} //if end
?>
<!DOCTYPE html>
<html lang="zh-tw">
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<script src="js/jquery.js"></script>
<script type="text/javascript">
// document.location.replace('formThanks');
</script>
</body>
</html>