Subversion Repositories php-qbpwcf

Rev

Rev 58 | Rev 237 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 58 Rev 226
Line 1... Line 1...
1
<?php
1
<?php
2
 
2
 
3
/*
3
/*
4
 
4
 
5
	QBPWCF, Quick Build PHP website Component base on Fedora Linux.
5
	QBPWCF, Quick Build PHP website Component base on Fedora Linux.
6
    Copyright (C) 2014~2025 Min-Jhin,Chen
6
    Copyright (C) 2014~2025 MIN ZHI, CHEN
7
 
7
 
8
    This file is part of QBPWCF.
8
    This file is part of QBPWCF.
9
 
9
 
10
    QBPWCF is free software: you can redistribute it and/or modify
10
    QBPWCF is free software: you can redistribute it and/or modify
11
    it under the terms of the GNU General Public License as published by
11
    it under the terms of the GNU General Public License as published by
Line 47... Line 47...
47
	#__call=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
47
	#__call=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
48
	#備註:
48
	#備註:
49
	#無.
49
	#無.
50
	*/
50
	*/
51
	public function __call($method,$arguments){
51
	public function __call($method,$arguments){
52
		
52
 
53
		#取得當前執行的函式
53
		#取得當前執行的函式
54
		$result["function"]=__FUNCTION__;
54
		$result["function"]=__FUNCTION__;
55
		
55
 
56
		#設置執行不正常
56
		#設置執行不正常
57
		$result["status"]="false";
57
		$result["status"]="false";
58
		
58
 
59
		#設置執行錯誤
59
		#設置執行錯誤
60
		$result["error"][]=__NAMESPACE__ ."/".$method."() 不存在!";
60
		$result["error"][]=__NAMESPACE__ ."/".$method."() 不存在!";
61
		
61
 
62
		#設置所丟入的參數
62
		#設置所丟入的參數
63
		$result["error"][]=$arguments;
63
		$result["error"][]=$arguments;
64
		
64
 
65
		#回傳結果
65
		#回傳結果
66
		return $result;
66
		return $result;
67
		
67
 
68
		}#function __call end
68
		}#function __call end
69
		
69
 
70
	/*
70
	/*
71
	#函式說明:
71
	#函式說明:
72
	#當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.
72
	#當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.
73
	#回傳結果:
73
	#回傳結果:
74
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
74
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
Line 83... Line 83...
83
	#__call=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
83
	#__call=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
84
	#備註:
84
	#備註:
85
	#無.
85
	#無.
86
	*/
86
	*/
87
	public static function __callStatic($method,$arguments){
87
	public static function __callStatic($method,$arguments){
88
		
88
 
89
		#取得當前執行的函式
89
		#取得當前執行的函式
90
		$result["function"]=__FUNCTION__;
90
		$result["function"]=__FUNCTION__;
91
		
91
 
92
		#設置執行不正常
92
		#設置執行不正常
93
		$result["status"]="false";
93
		$result["status"]="false";
94
		
94
 
95
		#設置執行錯誤
95
		#設置執行錯誤
96
		$result["error"][]="欲呼叫的". __NAMESPACE__ ."/".$method."() 不存在!";
96
		$result["error"][]="欲呼叫的". __NAMESPACE__ ."/".$method."() 不存在!";
97
		
97
 
98
		#設置所丟入的參數
98
		#設置所丟入的參數
99
		$result["error"][]=$arguments;
99
		$result["error"][]=$arguments;
100
		
100
 
101
		#回傳結果
101
		#回傳結果
102
		return $result;
102
		return $result;
103
		
103
 
104
		}#function __callStatic end
104
		}#function __callStatic end
105
	
105
 
106
	/*
106
	/*
107
	#函式說明:
107
	#函式說明:
108
	#登入 imap 信箱
108
	#登入 imap 信箱
109
	#回傳結果:
109
	#回傳結果:
110
	#$result["status"],寄信的情況,若爲"true",則十之八九沒有問題.
110
	#$result["status"],寄信的情況,若爲"true",則十之八九沒有問題.
Line 131... Line 131...
131
		#儲存當前執行的函數
131
		#儲存當前執行的函數
132
		$result["function"]=__FUNCTION__;
132
		$result["function"]=__FUNCTION__;
133
 
133
 
134
		#如果 $conf 不為陣列
134
		#如果 $conf 不為陣列
135
		if(gettype($conf)!="array"){
135
		if(gettype($conf)!="array"){
136
			
136
 
137
			#設置執行失敗
137
			#設置執行失敗
138
			$result["status"]="false";
138
			$result["status"]="false";
139
			
139
 
140
			#設置執行錯誤訊息
140
			#設置執行錯誤訊息
141
			$result["error"][]="\$conf變數須為陣列形態";
141
			$result["error"][]="\$conf變數須為陣列形態";
142
 
142
 
143
			#如果傳入的參數為 null
143
			#如果傳入的參數為 null
144
			if($conf==null){
144
			if($conf==null){
145
				
145
 
146
				#設置執行錯誤訊息
146
				#設置執行錯誤訊息
147
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
147
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
148
				
148
 
149
				}#if end
149
				}#if end
150
 
150
 
151
			#回傳結果
151
			#回傳結果
152
			return $result;
152
			return $result;
153
	
153
 
154
			}#if end
154
			}#if end
155
	
155
 
156
		#檢查參數
156
		#檢查參數
157
		#函式說明:
157
		#函式說明:
158
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
158
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
159
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
159
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
160
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
160
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
Line 169... Line 169...
169
		#必填寫的參數:
169
		#必填寫的參數:
170
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
170
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
171
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
171
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
172
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
172
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
173
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("username","password");
173
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("username","password");
174
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); 
174
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
175
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
175
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
176
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
176
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
177
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
177
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
178
		#可以省略的參數:
178
		#可以省略的參數:
179
		#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
179
		#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
180
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
180
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
181
		#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
181
		#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
182
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("mailServerPositionAndPort");
182
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("mailServerPositionAndPort");
183
		#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double"); 
183
		#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
184
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
184
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
185
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
185
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
186
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("imap.gmail.com:993");
186
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("imap.gmail.com:993");
187
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
187
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
188
		#$conf["arrayCountEqualCheck"][]=array();
188
		#$conf["arrayCountEqualCheck"][]=array();
189
		#參考資料來源:
189
		#參考資料來源:
190
		#array_keys=>http://php.net/manual/en/function.array-keys.php
190
		#array_keys=>http://php.net/manual/en/function.array-keys.php
191
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
191
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
192
		unset($conf["variableCheck::checkArguments"]);
192
		unset($conf["variableCheck::checkArguments"]);
193
	
193
 
194
		#如果檢查失敗
194
		#如果檢查失敗
195
		if($checkArguments["status"]=="false"){
195
		if($checkArguments["status"]=="false"){
196
			
196
 
197
			#設置錯誤識別
197
			#設置錯誤識別
198
			$result["status"]="false";
198
			$result["status"]="false";
199
			
199
 
200
			#設置錯誤訊息
200
			#設置錯誤訊息
201
			$result["error"]=$checkArguments;
201
			$result["error"]=$checkArguments;
202
			
202
 
203
			#回傳結果
203
			#回傳結果
204
			return $result;
204
			return $result;
205
			
205
 
206
			}#if end
206
			}#if end
207
	
207
 
208
		#如果檢查不通過
208
		#如果檢查不通過
209
		if($checkArguments["passed"]=="false"){
209
		if($checkArguments["passed"]=="false"){
210
			
210
 
211
			#設置錯誤識別
211
			#設置錯誤識別
212
			$result["status"]="false";
212
			$result["status"]="false";
213
			
213
 
214
			#設置錯誤訊息
214
			#設置錯誤訊息
215
			$result["error"]=$checkArguments;
215
			$result["error"]=$checkArguments;
216
			
216
 
217
			#回傳結果
217
			#回傳結果
218
			return $result;
218
			return $result;
219
			
219
 
220
			}#if end
220
			}#if end
221
 
221
 
222
		#To connect to an SSL IMAP or POP3 server, add /ssl after the protocol
222
		#To connect to an SSL IMAP or POP3 server, add /ssl after the protocol
223
		#specification:
223
		#specification:
224
		$mbox = \imap_open("{".$conf["mailServerPositionAndPort"]."/imap/ssl}INBOX",$conf["username"],$conf["password"]) or die("Cannot connect to mail server:".imap_last_error());
224
		$mbox = \imap_open("{".$conf["mailServerPositionAndPort"]."/imap/ssl}INBOX",$conf["username"],$conf["password"]) or die("Cannot connect to mail server:".imap_last_error());
225
 
225
 
226
		#如果 imap_open() 執行失敗
226
		#如果 imap_open() 執行失敗
227
		if($mbox["status"]==false){
227
		if($mbox["status"]==false){
228
			
228
 
229
			#設置執行不正常
229
			#設置執行不正常
230
			$result["status"]="false";
230
			$result["status"]="false";
231
			
231
 
232
			#設置錯誤訊息
232
			#設置錯誤訊息
233
			$result["error"]=\imap_last_error();
233
			$result["error"]=\imap_last_error();
234
			
234
 
235
			}#if end
235
			}#if end
236
 
236
 
237
		#儲存執行 imap_open() 後的 resource
237
		#儲存執行 imap_open() 後的 resource
238
		$result["content"]=$mbox;
238
		$result["content"]=$mbox;
239
 
239
 
Line 270... Line 270...
270
		#儲存當前執行的函數
270
		#儲存當前執行的函數
271
		$result["function"]=__FUNCTION__;
271
		$result["function"]=__FUNCTION__;
272
 
272
 
273
		#如果 $conf 不為陣列
273
		#如果 $conf 不為陣列
274
		if(gettype($conf)!="array"){
274
		if(gettype($conf)!="array"){
275
			
275
 
276
			#設置執行失敗
276
			#設置執行失敗
277
			$result["status"]="false";
277
			$result["status"]="false";
278
			
278
 
279
			#設置執行錯誤訊息
279
			#設置執行錯誤訊息
280
			$result["error"][]="\$conf變數須為陣列形態";
280
			$result["error"][]="\$conf變數須為陣列形態";
281
 
281
 
282
			#如果傳入的參數為 null
282
			#如果傳入的參數為 null
283
			if($conf==null){
283
			if($conf==null){
284
				
284
 
285
				#設置執行錯誤訊息
285
				#設置執行錯誤訊息
286
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
286
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
287
				
287
 
288
				}#if end
288
				}#if end
289
 
289
 
290
			#回傳結果
290
			#回傳結果
291
			return $result;
291
			return $result;
292
	
292
 
293
			}#if end
293
			}#if end
294
	
294
 
295
		#檢查參數
295
		#檢查參數
296
		#函式說明:
296
		#函式說明:
297
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
297
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
298
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
298
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
299
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
299
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
Line 308... Line 308...
308
		#必填寫的參數:
308
		#必填寫的參數:
309
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
309
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
310
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
310
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
311
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
311
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
312
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("mailConnection");
312
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("mailConnection");
313
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); 
313
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
314
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("resource");
314
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("resource");
315
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
315
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
316
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
316
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
317
		#可以省略的參數:
317
		#可以省略的參數:
318
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
318
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
319
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
319
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
320
		#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
320
		#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
321
		#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("mailServerPositionAndPort");
321
		#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("mailServerPositionAndPort");
322
		#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double"); 
322
		#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
323
		#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
323
		#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
324
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
324
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
325
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("imap.gmail.com:993");
325
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("imap.gmail.com:993");
326
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
326
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
327
		#$conf["arrayCountEqualCheck"][]=array();
327
		#$conf["arrayCountEqualCheck"][]=array();
328
		#參考資料來源:
328
		#參考資料來源:
329
		#array_keys=>http://php.net/manual/en/function.array-keys.php
329
		#array_keys=>http://php.net/manual/en/function.array-keys.php
330
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
330
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
331
		unset($conf["variableCheck::checkArguments"]);
331
		unset($conf["variableCheck::checkArguments"]);
332
	
332
 
333
		#如果檢查失敗
333
		#如果檢查失敗
334
		if($checkArguments["status"]=="false"){
334
		if($checkArguments["status"]=="false"){
335
			
335
 
336
			#設置錯誤識別
336
			#設置錯誤識別
337
			$result["status"]="false";
337
			$result["status"]="false";
338
			
338
 
339
			#設置錯誤訊息
339
			#設置錯誤訊息
340
			$result["error"]=$checkArguments;
340
			$result["error"]=$checkArguments;
341
			
341
 
342
			#回傳結果
342
			#回傳結果
343
			return $result;
343
			return $result;
344
			
344
 
345
			}#if end
345
			}#if end
346
	
346
 
347
		#如果檢查不通過
347
		#如果檢查不通過
348
		if($checkArguments["passed"]=="false"){
348
		if($checkArguments["passed"]=="false"){
349
			
349
 
350
			#設置錯誤識別
350
			#設置錯誤識別
351
			$result["status"]="false";
351
			$result["status"]="false";
352
			
352
 
353
			#設置錯誤訊息
353
			#設置錯誤訊息
354
			$result["error"]=$checkArguments;
354
			$result["error"]=$checkArguments;
355
			
355
 
356
			#回傳結果
356
			#回傳結果
357
			return $result;
357
			return $result;
358
			
358
 
359
			}#if end
359
			}#if end
360
 
360
 
361
		#如果中斷與mailServer的連線失敗
361
		#如果中斷與mailServer的連線失敗
362
		if(\imap_close($conf["mailConnection"])==false){
362
		if(\imap_close($conf["mailConnection"])==false){
363
			
363
 
364
			#設置執行不正常
364
			#設置執行不正常
365
			$result["status"]="false";
365
			$result["status"]="false";
366
			
366
 
367
			#設置錯誤訊息
367
			#設置錯誤訊息
368
			$result["error"][]="中斷與 imap Server 的連線失敗";
368
			$result["error"][]="中斷與 imap Server 的連線失敗";
369
			
369
 
370
			#回傳結果
370
			#回傳結果
371
			return $result;
371
			return $result;
372
			
372
 
373
			}#if end
373
			}#if end
374
			
374
 
375
		#設置執行正常
375
		#設置執行正常
376
		$result["status"]="true";
376
		$result["status"]="true";
377
		
377
 
378
		#回傳結果
378
		#回傳結果
379
		return $result;
379
		return $result;
380
 
380
 
381
		}#function imapLogout end
381
		}#function imapLogout end
382
 
382
 
Line 405... Line 405...
405
	#http://www.php.net/manual/en/function.imap-last-error.php
405
	#http://www.php.net/manual/en/function.imap-last-error.php
406
	#http://wiki.dreamhost.com/PHP_IMAP#Verify_PHP_INI_Settings
406
	#http://wiki.dreamhost.com/PHP_IMAP#Verify_PHP_INI_Settings
407
	#備註:
407
	#備註:
408
	#需要php-imap套件
408
	#需要php-imap套件
409
	#無法寄送成功?
409
	#無法寄送成功?
410
	*/		
410
	*/
411
	public static function mailTo(&$conf){
411
	public static function mailTo(&$conf){
412
 
412
 
413
		#初始化要回傳的結果
413
		#初始化要回傳的結果
414
		$result=array();
414
		$result=array();
415
 
415
 
416
		#儲存當前執行的函數
416
		#儲存當前執行的函數
417
		$result["function"]=__FUNCTION__;
417
		$result["function"]=__FUNCTION__;
418
 
418
 
419
		#如果 $conf 不為陣列
419
		#如果 $conf 不為陣列
420
		if(gettype($conf)!="array"){
420
		if(gettype($conf)!="array"){
421
			
421
 
422
			#設置執行失敗
422
			#設置執行失敗
423
			$result["status"]="false";
423
			$result["status"]="false";
424
			
424
 
425
			#設置執行錯誤訊息
425
			#設置執行錯誤訊息
426
			$result["error"][]="\$conf變數須為陣列形態";
426
			$result["error"][]="\$conf變數須為陣列形態";
427
 
427
 
428
			#如果傳入的參數為 null
428
			#如果傳入的參數為 null
429
			if($conf==null){
429
			if($conf==null){
430
				
430
 
431
				#設置執行錯誤訊息
431
				#設置執行錯誤訊息
432
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
432
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
433
				
433
 
434
				}#if end
434
				}#if end
435
 
435
 
436
			#回傳結果
436
			#回傳結果
437
			return $result;
437
			return $result;
438
	
438
 
439
			}#if end
439
			}#if end
440
	
440
 
441
		#檢查參數
441
		#檢查參數
442
		#函式說明:
442
		#函式說明:
443
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
443
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
444
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
444
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
445
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
445
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
Line 454... Line 454...
454
		#必填寫的參數:
454
		#必填寫的參數:
455
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
455
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
456
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
456
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
457
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
457
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
458
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("username","password","receiver","subject","body");
458
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("username","password","receiver","subject","body");
459
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); 
459
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
460
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string","string","string");
460
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string","string","string");
461
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
461
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
462
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
462
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
463
		#可以省略的參數:
463
		#可以省略的參數:
464
		#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
464
		#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
465
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
465
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
466
		#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
466
		#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
467
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("mailServerPositionAndPort","headerInfo","cc","bcc");
467
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("mailServerPositionAndPort","headerInfo","cc","bcc");
468
		#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double"); 
468
		#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
469
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","string");
469
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","string");
470
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
470
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
471
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,null,null,"\$conf[\"username\"]");
471
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,null,null,"\$conf[\"username\"]");
472
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
472
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
473
		#$conf["arrayCountEqualCheck"][]=array();
473
		#$conf["arrayCountEqualCheck"][]=array();
474
		#參考資料來源:
474
		#參考資料來源:
475
		#array_keys=>http://php.net/manual/en/function.array-keys.php
475
		#array_keys=>http://php.net/manual/en/function.array-keys.php
476
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
476
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
477
		unset($conf["variableCheck::checkArguments"]);
477
		unset($conf["variableCheck::checkArguments"]);
478
	
478
 
479
		#如果檢查失敗
479
		#如果檢查失敗
480
		if($checkArguments["status"]=="false"){
480
		if($checkArguments["status"]=="false"){
481
			
481
 
482
			#設置錯誤識別
482
			#設置錯誤識別
483
			$result["status"]="false";
483
			$result["status"]="false";
484
			
484
 
485
			#設置錯誤訊息
485
			#設置錯誤訊息
486
			$result["error"]=$checkArguments;
486
			$result["error"]=$checkArguments;
487
			
487
 
488
			#回傳結果
488
			#回傳結果
489
			return $result;
489
			return $result;
490
			
490
 
491
			}#if end
491
			}#if end
492
	
492
 
493
		#如果檢查不通過
493
		#如果檢查不通過
494
		if($checkArguments["passed"]=="false"){
494
		if($checkArguments["passed"]=="false"){
495
			
495
 
496
			#設置錯誤識別
496
			#設置錯誤識別
497
			$result["status"]="false";
497
			$result["status"]="false";
498
			
498
 
499
			#設置錯誤訊息
499
			#設置錯誤訊息
500
			$result["error"]=$checkArguments;
500
			$result["error"]=$checkArguments;
501
			
501
 
502
			#回傳結果
502
			#回傳結果
503
			return $result;
503
			return $result;
504
			
504
 
505
			}#if end
505
			}#if end
506
 
506
 
507
		#函式說明:
507
		#函式說明:
508
		#登入信箱
508
		#登入信箱
509
		#回傳結果:
509
		#回傳結果:
Line 513... Line 513...
513
		$conf["mail"]["login"]["password"]=$conf["password"];#使用者密碼
513
		$conf["mail"]["login"]["password"]=$conf["password"];#使用者密碼
514
		#可省略參數:
514
		#可省略參數:
515
 
515
 
516
		#若 $conf["mail"]["login"]["mailServerPositionAndPort"] 沒有設置,則預設爲gmail信箱
516
		#若 $conf["mail"]["login"]["mailServerPositionAndPort"] 沒有設置,則預設爲gmail信箱
517
		if(!isset($conf["mail"]["login"]["mailServerPositionAndPort"])){
517
		if(!isset($conf["mail"]["login"]["mailServerPositionAndPort"])){
518
			
518
 
519
			$conf["mail"]["login"]["mailServerPositionAndPort"]="imap.gmail.com:993";
519
			$conf["mail"]["login"]["mailServerPositionAndPort"]="imap.gmail.com:993";
520
 
520
 
521
			}#if end
521
			}#if end
522
 
522
 
523
		#反之有設定,則採用指定值
523
		#反之有設定,則採用指定值
Line 534... Line 534...
534
		$mailConnection=mail::imapLogin($conf["mail"]["login"]);
534
		$mailConnection=mail::imapLogin($conf["mail"]["login"]);
535
		unset($conf["mail"]["login"]);
535
		unset($conf["mail"]["login"]);
536
 
536
 
537
		#如果登入imap伺服器失敗
537
		#如果登入imap伺服器失敗
538
		if($mailConnection["status"]=="false"){
538
		if($mailConnection["status"]=="false"){
539
			
539
 
540
			#設置錯誤訊息
540
			#設置錯誤訊息
541
			$result["error"]=$mailConnection;
541
			$result["error"]=$mailConnection;
542
			
542
 
543
			#設置執行失敗
543
			#設置執行失敗
544
			$result["status"]="false";
544
			$result["status"]="false";
545
			
545
 
546
			#回傳結果
546
			#回傳結果
547
			return $result;
547
			return $result;
548
			
548
 
549
			}#if end
549
			}#if end
550
 
550
 
551
		#如果 $conf["headerInfo"] 沒有指定
551
		#如果 $conf["headerInfo"] 沒有指定
552
		if(!isset($conf["headerInfo"])){
552
		if(!isset($conf["headerInfo"])){
553
 
553
 
Line 563... Line 563...
563
 
563
 
564
			}#if end
564
			}#if end
565
 
565
 
566
		#用imap寄出信件
566
		#用imap寄出信件
567
		$result["mailToStatus"]=\imap_mail($conf["receiver"],imap_utf8($conf["subject"]),imap_utf8($conf["body"]),imap_utf8($conf["headerInfo"]),imap_utf8($conf["cc"]),imap_utf8($conf["bcc"]),imap_utf8($conf["username"]));
567
		$result["mailToStatus"]=\imap_mail($conf["receiver"],imap_utf8($conf["subject"]),imap_utf8($conf["body"]),imap_utf8($conf["headerInfo"]),imap_utf8($conf["cc"]),imap_utf8($conf["bcc"]),imap_utf8($conf["username"]));
568
			
568
 
569
		#取得使用imap服務與到的警示訊息
569
		#取得使用imap服務與到的警示訊息
570
		$result["imapAlerts"]=\imap_alerts();
570
		$result["imapAlerts"]=\imap_alerts();
571
 
571
 
572
		#取得使用imap服務與到的錯誤訊息
572
		#取得使用imap服務與到的錯誤訊息
573
		$result["imapErrors"]=\imap_errors();
573
		$result["imapErrors"]=\imap_errors();
Line 585... Line 585...
585
		$imapLogout=mail::imapLogout($conf["mail"]["logout"]);
585
		$imapLogout=mail::imapLogout($conf["mail"]["logout"]);
586
		unset($conf["mail"]["logout"]);
586
		unset($conf["mail"]["logout"]);
587
 
587
 
588
		#如果登出imap伺服器失敗
588
		#如果登出imap伺服器失敗
589
		if($imapLogout["status"]=="false"){
589
		if($imapLogout["status"]=="false"){
590
			
590
 
591
			#設置執行失敗
591
			#設置執行失敗
592
			$result["status"]="false";
592
			$result["status"]="false";
593
			
593
 
594
			#設置錯誤訊息
594
			#設置錯誤訊息
595
			$result["error"]=$imapLogout;
595
			$result["error"]=$imapLogout;
596
			
596
 
597
			#回傳結果
597
			#回傳結果
598
			return $result;
598
			return $result;
599
			
599
 
600
			}#if end
600
			}#if end
601
 
601
 
602
		#設置執行正常
602
		#設置執行正常
603
		$result["status"]="true";
603
		$result["status"]="true";
604
 
604
 
Line 675... Line 675...
675
		#儲存當前執行的函數
675
		#儲存當前執行的函數
676
		$result["function"]=__FUNCTION__;
676
		$result["function"]=__FUNCTION__;
677
 
677
 
678
		#如果 $conf 不為陣列
678
		#如果 $conf 不為陣列
679
		if(gettype($conf)!="array"){
679
		if(gettype($conf)!="array"){
680
			
680
 
681
			#設置執行失敗
681
			#設置執行失敗
682
			$result["status"]="false";
682
			$result["status"]="false";
683
			
683
 
684
			#設置執行錯誤訊息
684
			#設置執行錯誤訊息
685
			$result["error"][]="\$conf變數須為陣列形態";
685
			$result["error"][]="\$conf變數須為陣列形態";
686
 
686
 
687
			#如果傳入的參數為 null
687
			#如果傳入的參數為 null
688
			if($conf==null){
688
			if($conf==null){
689
				
689
 
690
				#設置執行錯誤訊息
690
				#設置執行錯誤訊息
691
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
691
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
692
				
692
 
693
				}#if end
693
				}#if end
694
 
694
 
695
			#回傳結果
695
			#回傳結果
696
			return $result;
696
			return $result;
697
	
697
 
698
			}#if end
698
			}#if end
699
	
699
 
700
		#檢查參數
700
		#檢查參數
701
		#函式說明:
701
		#函式說明:
702
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
702
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
703
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
703
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
704
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
704
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
Line 713... Line 713...
713
		#必填寫的參數:
713
		#必填寫的參數:
714
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
714
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
715
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
715
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
716
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
716
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
717
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("username","password","receiverMail","subject","plainBody","htmlBody","fileArgu");
717
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("username","password","receiverMail","subject","plainBody","htmlBody","fileArgu");
718
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); 
718
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
719
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","array","string","string","string","string");
719
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","array","string","string","string","string");
720
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
720
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
721
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
721
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
722
		#可以省略的參數:
722
		#可以省略的參數:
723
		#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
723
		#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
724
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
724
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
725
		#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
725
		#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
726
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("attachment","attachmentName","attachmentMimeType","mailServer","mailerMailDisplay","mailerNameDisplay","receiverMailDisplay","receiverNameDisplay","levelForCheckSSL");
726
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("attachment","attachmentName","attachmentMimeType","mailServer","mailerMailDisplay","mailerNameDisplay","receiverMailDisplay","receiverNameDisplay","levelForCheckSSL");
727
		#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double"); 
727
		#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
728
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array","array","array","string","string","string","string","string","string");
728
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array","array","array","string","string","string","string","string","string");
729
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
729
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
730
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,null,null,"smtps://smtp.gmail.com:465","\$conf[\"username\"]","\$conf[\"username\"]","\$conf[\"receiverMail\"]","\$conf[\"receiverMail\"]","force");
730
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,null,null,"smtps://smtp.gmail.com:465","\$conf[\"username\"]","\$conf[\"username\"]","\$conf[\"receiverMail\"]","\$conf[\"receiverMail\"]","force");
731
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
731
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
732
		$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("receiverMail","receiverMailDisplay","receiverNameDisplay");
732
		$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("receiverMail","receiverMailDisplay","receiverNameDisplay");
733
		#參考資料來源:
733
		#參考資料來源:
734
		#array_keys=>http://php.net/manual/en/function.array-keys.php
734
		#array_keys=>http://php.net/manual/en/function.array-keys.php
735
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
735
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
736
		unset($conf["variableCheck::checkArguments"]);
736
		unset($conf["variableCheck::checkArguments"]);
737
	
737
 
738
		#如果檢查失敗
738
		#如果檢查失敗
739
		if($checkArguments["status"]=="false"){
739
		if($checkArguments["status"]=="false"){
740
			
740
 
741
			#設置錯誤識別
741
			#設置錯誤識別
742
			$result["status"]="false";
742
			$result["status"]="false";
743
			
743
 
744
			#設置錯誤訊息
744
			#設置錯誤訊息
745
			$result["error"]=$checkArguments;
745
			$result["error"]=$checkArguments;
746
			
746
 
747
			#回傳結果
747
			#回傳結果
748
			return $result;
748
			return $result;
749
			
749
 
750
			}#if end
750
			}#if end
751
	
751
 
752
		#如果檢查不通過
752
		#如果檢查不通過
753
		if($checkArguments["passed"]=="false"){
753
		if($checkArguments["passed"]=="false"){
754
			
754
 
755
			#設置錯誤識別
755
			#設置錯誤識別
756
			$result["status"]="false";
756
			$result["status"]="false";
757
			
757
 
758
			#設置錯誤訊息
758
			#設置錯誤訊息
759
			$result["error"]=$checkArguments;
759
			$result["error"]=$checkArguments;
760
			
760
 
761
			#回傳結果
761
			#回傳結果
762
			return $result;
762
			return $result;
763
			
763
 
764
			}#if end
764
			}#if end
765
	
765
 
766
		#檢查 curlSmtp 資料夾是否存在
766
		#檢查 curlSmtp 資料夾是否存在
767
		#函式說明:檢查多個檔案是否存在
767
		#函式說明:檢查多個檔案是否存在
768
		#回傳的結果:
768
		#回傳的結果:
769
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
769
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
770
		#$result["error"],錯誤訊息陣列.
770
		#$result["error"],錯誤訊息陣列.
Line 778... Line 778...
778
		#參考資料來源:
778
		#參考資料來源:
779
		#http://php.net/manual/en/function.file-exists.php
779
		#http://php.net/manual/en/function.file-exists.php
780
		#http://php.net/manual/en/control-structures.foreach.php
780
		#http://php.net/manual/en/control-structures.foreach.php
781
		$checkMutiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
781
		$checkMutiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
782
		unset($conf["fileAccess::checkMultiFileExist"]);
782
		unset($conf["fileAccess::checkMultiFileExist"]);
783
		
783
 
784
		#如果檢查檔案失敗
784
		#如果檢查檔案失敗
785
		if($checkMutiFileExist["status"]=="false"){
785
		if($checkMutiFileExist["status"]=="false"){
786
			
786
 
787
			#設置錯誤識別
787
			#設置錯誤識別
788
			$result["status"]="false";
788
			$result["status"]="false";
789
			
789
 
790
			#設置錯誤訊息
790
			#設置錯誤訊息
791
			$result["error"]=$checkMutiFileExist;
791
			$result["error"]=$checkMutiFileExist;
792
			
792
 
793
			#回傳結果
793
			#回傳結果
794
			return $result;
794
			return $result;
795
			
795
 
796
			}#if end
796
			}#if end
797
 
797
 
798
		#如果該資料夾不存在
798
		#如果該資料夾不存在
799
		if($checkMutiFileExist["varExist"][0]=="false"){
799
		if($checkMutiFileExist["varExist"][0]=="false"){
800
 
800
 
Line 809... Line 809...
809
			$conf["fileAccess::createFolderAfterCheck"]["fileArgu"]=$conf["fileArgu"];
809
			$conf["fileAccess::createFolderAfterCheck"]["fileArgu"]=$conf["fileArgu"];
810
			#可省略參數:
810
			#可省略參數:
811
			#$conf["fileAccess::createFolderAfterCheck"]["dirPermission"]="";#新建資料夾的權限設定,預設爲0770,亦即擁有者,同群組者可以讀,寫,存取,其他人僅能存取.
811
			#$conf["fileAccess::createFolderAfterCheck"]["dirPermission"]="";#新建資料夾的權限設定,預設爲0770,亦即擁有者,同群組者可以讀,寫,存取,其他人僅能存取.
812
			$createFolderAfterCheck=fileAccess::createFolderAfterCheck($conf["fileAccess::createFolderAfterCheck"]);
812
			$createFolderAfterCheck=fileAccess::createFolderAfterCheck($conf["fileAccess::createFolderAfterCheck"]);
813
			unset($conf["fileAccess::createFolderAfterCheck"]);
813
			unset($conf["fileAccess::createFolderAfterCheck"]);
814
			
814
 
815
			#如果 建立資料夾失敗
815
			#如果 建立資料夾失敗
816
			if($createFolderAfterCheck["status"]=="false"){
816
			if($createFolderAfterCheck["status"]=="false"){
817
 
817
 
818
				#設置錯誤識別
818
				#設置錯誤識別
819
				$result["status"]="false";
819
				$result["status"]="false";
Line 825... Line 825...
825
				return $result;
825
				return $result;
826
 
826
 
827
				}#if end
827
				}#if end
828
 
828
 
829
			}#if end
829
			}#if end
830
		
830
 
831
		#取得 $systemTime
831
		#取得 $systemTime
832
		$systemTime=time::getMicrotime();
832
		$systemTime=time::getMicrotime();
833
 
833
 
834
		#要傳送的信件資訊
834
		#要傳送的信件資訊
835
		$mailFileHeader="From: ".$conf["mailerNameDisplay"]." <".$conf["mailerMailDisplay"].">\r\n";
835
		$mailFileHeader="From: ".$conf["mailerNameDisplay"]." <".$conf["mailerMailDisplay"].">\r\n";
836
		
836
 
837
		#第一個人主要收件人
837
		#第一個人主要收件人
838
		$mailFileHeader=$mailFileHeader."To: ".$conf["receiverNameDisplay"][0]." "."<".$conf["receiverMailDisplay"][0].">\r\n";			
838
		$mailFileHeader=$mailFileHeader."To: ".$conf["receiverNameDisplay"][0]." "."<".$conf["receiverMailDisplay"][0].">\r\n";
839
		
839
 
840
		#如果有其餘收件人
840
		#如果有其餘收件人
841
		if(count($conf["receiverNameDisplay"])>1){
841
		if(count($conf["receiverNameDisplay"])>1){
842
			
842
 
843
			#副本寄送處的資訊開始
843
			#副本寄送處的資訊開始
844
			$mailFileHeader=$mailFileHeader."Cc: ";
844
			$mailFileHeader=$mailFileHeader."Cc: ";
845
			
845
 
846
			}#if end
846
			}#if end
847
		
847
 
848
		#針對其餘收件人的地址
848
		#針對其餘收件人的地址
849
		for($i=1;$i<count($conf["receiverNameDisplay"]);$i++){
849
		for($i=1;$i<count($conf["receiverNameDisplay"]);$i++){
850
			
850
 
851
			#如果不是最後一筆
851
			#如果不是最後一筆
852
			if($i!=count($conf["receiverNameDisplay"])-1){
852
			if($i!=count($conf["receiverNameDisplay"])-1){
853
				
853
 
854
				$mailFileHeader=$mailFileHeader.$conf["receiverNameDisplay"][$i]." <".$conf["receiverMailDisplay"][$i].">,";
854
				$mailFileHeader=$mailFileHeader.$conf["receiverNameDisplay"][$i]." <".$conf["receiverMailDisplay"][$i].">,";
855
				
855
 
856
				}#if end
856
				}#if end
857
			
857
 
858
			#反之是最後一筆
858
			#反之是最後一筆
859
			else{
859
			else{
860
				
860
 
861
				$mailFileHeader=$mailFileHeader.$conf["receiverNameDisplay"][$i]." <".$conf["receiverMailDisplay"][$i].">\r\n";
861
				$mailFileHeader=$mailFileHeader.$conf["receiverNameDisplay"][$i]." <".$conf["receiverMailDisplay"][$i].">\r\n";
862
				
862
 
863
				}#else end				
863
				}#else end
864
			
864
 
865
			}#for end
865
			}#for end
866
		
866
 
867
		$mailFileHeader=$mailFileHeader."Subject: ".$conf["subject"]."\r\n";
867
		$mailFileHeader=$mailFileHeader."Subject: ".$conf["subject"]."\r\n";
868
	
868
 
869
		#初始化信件本文
869
		#初始化信件本文
870
		$mailFileContent="";
870
		$mailFileContent="";
871
			
871
 
872
		#初始化 boundary
872
		#初始化 boundary
873
		$boundary="001a11c30ce8aec3480533bfa9a9";
873
		$boundary="001a11c30ce8aec3480533bfa9a9";
874
		
874
 
875
		#初始化 boundary start
875
		#初始化 boundary start
876
		$boundaryS="--".$boundary;
876
		$boundaryS="--".$boundary;
877
		
877
 
878
		#初始化 boundary end	
878
		#初始化 boundary end
879
		$boundaryE=$boundaryS."--";
879
		$boundaryE=$boundaryS."--";
880
					
880
 
881
		#設置信件本文(純文字與html兩種)				
881
		#設置信件本文(純文字與html兩種)
882
		$mailFileContent=$mailFileContent."Content-Type: multipart/alternative; boundary=\"".$boundary."\"\r\n";
882
		$mailFileContent=$mailFileContent."Content-Type: multipart/alternative; boundary=\"".$boundary."\"\r\n";
883
		$mailFileContent=$mailFileContent."\r\n";
883
		$mailFileContent=$mailFileContent."\r\n";
884
		$mailFileContent=$mailFileContent.$boundaryS."\r\n";
884
		$mailFileContent=$mailFileContent.$boundaryS."\r\n";
885
		$mailFileContent=$mailFileContent."Content-Type: text/plain; charset=UTF-8\r\n";
885
		$mailFileContent=$mailFileContent."Content-Type: text/plain; charset=UTF-8\r\n";
886
		$mailFileContent=$mailFileContent."\r\n";
886
		$mailFileContent=$mailFileContent."\r\n";
Line 888... Line 888...
888
		$mailFileContent=$mailFileContent."\r\n";
888
		$mailFileContent=$mailFileContent."\r\n";
889
		$mailFileContent=$mailFileContent.$boundaryS."\r\n";
889
		$mailFileContent=$mailFileContent.$boundaryS."\r\n";
890
		$mailFileContent=$mailFileContent."Content-Type: text/html; charset=UTF-8\r\n";
890
		$mailFileContent=$mailFileContent."Content-Type: text/html; charset=UTF-8\r\n";
891
		$mailFileContent=$mailFileContent."\r\n";
891
		$mailFileContent=$mailFileContent."\r\n";
892
		$mailFileContent=$mailFileContent.$conf["htmlBody"]."\r\n";
892
		$mailFileContent=$mailFileContent.$conf["htmlBody"]."\r\n";
893
		$mailFileContent=$mailFileContent.$boundaryE."\r\n";			
893
		$mailFileContent=$mailFileContent.$boundaryE."\r\n";
894
		
894
 
895
		#依據規定,每列不得大於70的字元
895
		#依據規定,每列不得大於70的字元
896
		$mailFileContent==wordwrap($mailFileContent,70,"\r\n",true);
896
		$mailFileContent==wordwrap($mailFileContent,70,"\r\n",true);
897
		
897
 
898
		#如果有設定要上傳附件
898
		#如果有設定要上傳附件
899
		if(isset($conf["attachment"])){
899
		if(isset($conf["attachment"])){
900
					
900
 
901
			#依據每個附件
901
			#依據每個附件
902
			for($i=0;$i<count($conf["attachment"]);$i++){
902
			for($i=0;$i<count($conf["attachment"]);$i++){
903
				
903
 
904
				#初始化寄送附件的語法
904
				#初始化寄送附件的語法
905
				$attachment="";
905
				$attachment="";
906
				
906
 
907
				#確認目標檔案是否存在
907
				#確認目標檔案是否存在
908
				#函式說明:檢查多個檔案是否存在
908
				#函式說明:檢查多個檔案是否存在
909
				#回傳的結果:
909
				#回傳的結果:
910
				#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
910
				#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
911
				#$result["error"],錯誤訊息陣列.
911
				#$result["error"],錯誤訊息陣列.
Line 919... Line 919...
919
				#參考資料來源:
919
				#參考資料來源:
920
				#http://php.net/manual/en/function.file-exists.php
920
				#http://php.net/manual/en/function.file-exists.php
921
				#http://php.net/manual/en/control-structures.foreach.php
921
				#http://php.net/manual/en/control-structures.foreach.php
922
				$checkMutiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
922
				$checkMutiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
923
				unset($conf["fileAccess::checkMultiFileExist"]);
923
				unset($conf["fileAccess::checkMultiFileExist"]);
924
					
924
 
925
				#如果檢查失敗
925
				#如果檢查失敗
926
				if($checkMutiFileExist["status"]=="false"){
926
				if($checkMutiFileExist["status"]=="false"){
927
					
927
 
928
					#設置錯誤識別
928
					#設置錯誤識別
929
					$result["status"]="false";
929
					$result["status"]="false";
930
 
930
 
931
					#設置錯誤資訊
931
					#設置錯誤資訊
932
					$result["error"]=$checkMutiFileExist;
932
					$result["error"]=$checkMutiFileExist;
933
 
933
 
934
					#回傳結果
934
					#回傳結果
935
					return $result;
935
					return $result;
936
					
936
 
937
					}#if end
937
					}#if end
938
					
938
 
939
				#如果檔案不存在
939
				#如果檔案不存在
940
				if($checkMutiFileExist["varExist"][0]=="false"){
940
				if($checkMutiFileExist["varExist"][0]=="false"){
941
					
941
 
942
					#設置錯誤識別
942
					#設置錯誤識別
943
					$result["status"]="false";
943
					$result["status"]="false";
944
 
944
 
945
					#設置錯誤資訊
945
					#設置錯誤資訊
946
					$result["error"]=$checkMutiFileExist;
946
					$result["error"]=$checkMutiFileExist;
947
 
947
 
948
					#回傳結果
948
					#回傳結果
949
					return $result;
949
					return $result;
950
					
950
 
951
					}#if end
951
					}#if end
952
					
952
 
953
				#如果是第一個附件
953
				#如果是第一個附件
954
				if($i==0){
954
				if($i==0){
955
					
955
 
956
					#在前面加上 multipart/mixed 的 boundary
956
					#在前面加上 multipart/mixed 的 boundary
957
					$mailFileContent="Content-Type: multipart/mixed; boundary=".$boundary."\r\n\r\n".$mailFileContent;
957
					$mailFileContent="Content-Type: multipart/mixed; boundary=".$boundary."\r\n\r\n".$mailFileContent;
958
					
958
 
959
					}#if end
959
					}#if end
960
					
960
 
961
				#如果 $conf["attachmentName"] 不存在
961
				#如果 $conf["attachmentName"] 不存在
962
				if(!isset($conf["attachmentName"])){
962
				if(!isset($conf["attachmentName"])){
963
					
963
 
964
					#涵是說明:
964
					#涵是說明:
965
					#取得檔案路徑字串的路徑與檔案的名稱與檔案副檔名
965
					#取得檔案路徑字串的路徑與檔案的名稱與檔案副檔名
966
					#回傳的結果:
966
					#回傳的結果:
967
					#$result["status"],執行是否正常,"true"正常,"false"代表不正常.
967
					#$result["status"],執行是否正常,"true"正常,"false"代表不正常.
968
					#$result["error"],錯誤訊息.
968
					#$result["error"],錯誤訊息.
Line 977... Line 977...
977
					$conf["fileAccess::getFileAddressAndNameAndFileExtention"]["fileAddressAndName"]=$conf["attachment"][$i];
977
					$conf["fileAccess::getFileAddressAndNameAndFileExtention"]["fileAddressAndName"]=$conf["attachment"][$i];
978
					#可省略的參數:
978
					#可省略的參數:
979
					#無.
979
					#無.
980
					$getFileAddressAndNameAndFileExtention=fileAccess::getFileAddressAndNameAndFileExtention($conf["fileAccess::getFileAddressAndNameAndFileExtention"]);
980
					$getFileAddressAndNameAndFileExtention=fileAccess::getFileAddressAndNameAndFileExtention($conf["fileAccess::getFileAddressAndNameAndFileExtention"]);
981
					unset($conf["fileAccess::getFileAddressAndNameAndFileExtention"]);
981
					unset($conf["fileAccess::getFileAddressAndNameAndFileExtention"]);
982
							
982
 
983
					#如果解析檔案資訊失敗		
983
					#如果解析檔案資訊失敗
984
					if($getFileAddressAndNameAndFileExtention["status"]=="false"){
984
					if($getFileAddressAndNameAndFileExtention["status"]=="false"){
985
						
985
 
986
						#設置錯誤識別
986
						#設置錯誤識別
987
						$result["status"]="false";
987
						$result["status"]="false";
988
 
988
 
989
						#設置錯誤資訊
989
						#設置錯誤資訊
990
						$result["error"]=$getFileAddressAndNameAndFileExtention;
990
						$result["error"]=$getFileAddressAndNameAndFileExtention;
991
 
991
 
992
						#回傳結果
992
						#回傳結果
993
						return $result;
993
						return $result;
994
						
994
 
995
						}#if end			
995
						}#if end
996
									
996
 
997
					#設定附件名稱
997
					#設定附件名稱
998
					$conf["attachmentName"][$i]=$getFileAddressAndNameAndFileExtention["fullFileName"];
998
					$conf["attachmentName"][$i]=$getFileAddressAndNameAndFileExtention["fullFileName"];
999
					
999
 
1000
					}#if end
1000
					}#if end
1001
					
1001
 
1002
				#反之如果 $conf["attachmentName"][$i] 不存在
1002
				#反之如果 $conf["attachmentName"][$i] 不存在
1003
				else if(!isset($conf["attachmentName"][$i])){
1003
				else if(!isset($conf["attachmentName"][$i])){
1004
					
1004
 
1005
					#涵是說明:
1005
					#涵是說明:
1006
					#取得檔案路徑字串的路徑與檔案的名稱與檔案副檔名
1006
					#取得檔案路徑字串的路徑與檔案的名稱與檔案副檔名
1007
					#回傳的結果:
1007
					#回傳的結果:
1008
					#$result["status"],執行是否正常,"true"正常,"false"代表不正常.
1008
					#$result["status"],執行是否正常,"true"正常,"false"代表不正常.
1009
					#$result["error"],錯誤訊息.
1009
					#$result["error"],錯誤訊息.
Line 1018... Line 1018...
1018
					$conf["fileAccess::getFileAddressAndNameAndFileExtention"]["fileAddressAndName"]=$conf["attachment"][$i];
1018
					$conf["fileAccess::getFileAddressAndNameAndFileExtention"]["fileAddressAndName"]=$conf["attachment"][$i];
1019
					#可省略的參數:
1019
					#可省略的參數:
1020
					#無.
1020
					#無.
1021
					$getFileAddressAndNameAndFileExtention=fileAccess::getFileAddressAndNameAndFileExtention($conf["fileAccess::getFileAddressAndNameAndFileExtention"]);
1021
					$getFileAddressAndNameAndFileExtention=fileAccess::getFileAddressAndNameAndFileExtention($conf["fileAccess::getFileAddressAndNameAndFileExtention"]);
1022
					unset($conf["fileAccess::getFileAddressAndNameAndFileExtention"]);
1022
					unset($conf["fileAccess::getFileAddressAndNameAndFileExtention"]);
1023
							
1023
 
1024
					#如果解析檔案資訊失敗		
1024
					#如果解析檔案資訊失敗
1025
					if($getFileAddressAndNameAndFileExtention["status"]=="false"){
1025
					if($getFileAddressAndNameAndFileExtention["status"]=="false"){
1026
						
1026
 
1027
						#設置錯誤識別
1027
						#設置錯誤識別
1028
						$result["status"]="false";
1028
						$result["status"]="false";
1029
 
1029
 
1030
						#設置錯誤資訊
1030
						#設置錯誤資訊
1031
						$result["error"]=$getFileAddressAndNameAndFileExtention;
1031
						$result["error"]=$getFileAddressAndNameAndFileExtention;
1032
 
1032
 
1033
						#回傳結果
1033
						#回傳結果
1034
						return $result;
1034
						return $result;
1035
						
1035
 
1036
						}#if end			
1036
						}#if end
1037
									
1037
 
1038
					#設定附件名稱
1038
					#設定附件名稱
1039
					$conf["attachmentName"][$i]=$getFileAddressAndNameAndFileExtention["fullFileName"];
1039
					$conf["attachmentName"][$i]=$getFileAddressAndNameAndFileExtention["fullFileName"];
1040
					
1040
 
1041
					}#if end
1041
					}#if end
1042
					
1042
 
1043
				#如果 $conf["attachmentMimeType"] 不存在
1043
				#如果 $conf["attachmentMimeType"] 不存在
1044
				if(!isset($conf["attachmentMimeType"])){
1044
				if(!isset($conf["attachmentMimeType"])){
1045
					
1045
 
1046
					#設定檔案類型
1046
					#設定檔案類型
1047
					$conf["attachmentMimeType"][$i]="application/*";
1047
					$conf["attachmentMimeType"][$i]="application/*";
1048
														
1048
 
1049
					}#if end	
1049
					}#if end
1050
					
1050
 
1051
				#反之如果 $conf["attachmentMimeType"][$i] 不存在	
1051
				#反之如果 $conf["attachmentMimeType"][$i] 不存在
1052
				if(!isset($conf["attachmentMimeType"][$i])){
1052
				if(!isset($conf["attachmentMimeType"][$i])){
1053
					
1053
 
1054
					$conf["attachmentMimeType"][$i]="application/*";
1054
					$conf["attachmentMimeType"][$i]="application/*";
1055
					
1055
 
1056
					}#if end
1056
					}#if end
1057
				
1057
 
1058
				#加上寄送附件的語法
1058
				#加上寄送附件的語法
1059
				$attachment=$attachment.$boundaryS."\r\n";
1059
				$attachment=$attachment.$boundaryS."\r\n";
1060
				$attachment=$attachment."Content-Type: ".$conf["attachmentMimeType"][$i]."; name=".$conf["attachmentName"][$i]."\r\n";
1060
				$attachment=$attachment."Content-Type: ".$conf["attachmentMimeType"][$i]."; name=".$conf["attachmentName"][$i]."\r\n";
1061
				$attachment=$attachment."Content-Disposition: attachment; filename=".$conf["attachmentName"][$i]."\r\n";
1061
				$attachment=$attachment."Content-Disposition: attachment; filename=".$conf["attachmentName"][$i]."\r\n";
1062
				$attachment=$attachment."Content-Transfer-Encoding: base64\r\n";			
1062
				$attachment=$attachment."Content-Transfer-Encoding: base64\r\n";
1063
				$attachment=$attachment."X-Attachment-Id: f_io1ikfii".$i."\r\n";
1063
				$attachment=$attachment."X-Attachment-Id: f_io1ikfii".$i."\r\n";
1064
					
1064
 
1065
				#將檔案用base64加密					
1065
				#將檔案用base64加密
1066
				$base64fileStr=base64_encode(file_get_contents($conf["attachment"][$i]));
1066
				$base64fileStr=base64_encode(file_get_contents($conf["attachment"][$i]));
1067
				
1067
 
1068
				#依據規定,每列不得大於70的字元
1068
				#依據規定,每列不得大於70的字元
1069
				$wordwrapedFileStr=wordwrap($base64fileStr,70,"\r\n",true);
1069
				$wordwrapedFileStr=wordwrap($base64fileStr,70,"\r\n",true);
1070
				
1070
 
1071
				#斷行後附加檔案字串
1071
				#斷行後附加檔案字串
1072
				$attachment=$attachment."\r\n".$wordwrapedFileStr."\r\n";	
1072
				$attachment=$attachment."\r\n".$wordwrapedFileStr."\r\n";
1073
					
1073
 
1074
				#如果是最後一個附件
1074
				#如果是最後一個附件
1075
				if($i==count($conf["attachment"])-1){
1075
				if($i==count($conf["attachment"])-1){
1076
					
1076
 
1077
					#混合資料結尾
1077
					#混合資料結尾
1078
					$attachment=$attachment.$boundary."\r\n";
1078
					$attachment=$attachment.$boundary."\r\n";
1079
					
1079
 
1080
					}#if end	
1080
					}#if end
1081
						
1081
 
1082
				#增加到信件內文的結尾
1082
				#增加到信件內文的結尾
1083
				$mailFileContent=$mailFileContent.$attachment;
1083
				$mailFileContent=$mailFileContent.$attachment;
1084
				
1084
 
1085
				}#for end
1085
				}#for end
1086
								
1086
 
1087
			}#if end
1087
			}#if end
1088
		
1088
 
1089
		#建立要寄送的郵件檔案
1089
		#建立要寄送的郵件檔案
1090
		#函式說明:
1090
		#函式說明:
1091
		#建立暫存目錄與回傳暫存檔案名稱路徑 
1091
		#建立暫存目錄與回傳暫存檔案名稱路徑
1092
		#回傳結果:
1092
		#回傳結果:
1093
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1093
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1094
		#$result["error"],錯誤訊息.
1094
		#$result["error"],錯誤訊息.
1095
		#$result["function"],當前執行的函數名稱.
1095
		#$result["function"],當前執行的函數名稱.
1096
		#$result["content"],暫存檔案的路徑與名稱.
1096
		#$result["content"],暫存檔案的路徑與名稱.
Line 1103... Line 1103...
1103
		#備註:
1103
		#備註:
1104
		#無.
1104
		#無.
1105
		$conf["conffileAccess::createTempFile"]=array();
1105
		$conf["conffileAccess::createTempFile"]=array();
1106
		$createTempFile=fileAccess::createTempFile($conf["conffileAccess::createTempFile"]);
1106
		$createTempFile=fileAccess::createTempFile($conf["conffileAccess::createTempFile"]);
1107
		unset($conf["conffileAccess::createTempFile"]);
1107
		unset($conf["conffileAccess::createTempFile"]);
1108
		
1108
 
1109
		#如果檔案建立失敗
1109
		#如果檔案建立失敗
1110
		if($createTempFile["status"]=="false"){
1110
		if($createTempFile["status"]=="false"){
1111
 
1111
 
1112
			#設置錯誤識別
1112
			#設置錯誤識別
1113
			$result["status"]="false";
1113
			$result["status"]="false";
Line 1117... Line 1117...
1117
 
1117
 
1118
			#回傳結果
1118
			#回傳結果
1119
			return $result;
1119
			return $result;
1120
 
1120
 
1121
			}#if end
1121
			}#if end
1122
		
1122
 
1123
		#取得要寄送的郵件檔案
1123
		#取得要寄送的郵件檔案
1124
		$mailFile=$createTempFile["content"];
1124
		$mailFile=$createTempFile["content"];
1125
		
1125
 
1126
		#將字串寫入到檔案
1126
		#將字串寫入到檔案
1127
		#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
1127
		#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
1128
		#$result["error"],錯誤訊息陣列.
1128
		#$result["error"],錯誤訊息陣列.
1129
		#必填參數:
1129
		#必填參數:
1130
		$conf["fileAccess::writeTextIntoFile"]["fileName"]=$mailFile;#爲要編輯的檔案名稱
1130
		$conf["fileAccess::writeTextIntoFile"]["fileName"]=$mailFile;#爲要編輯的檔案名稱
Line 1151... Line 1151...
1151
 
1151
 
1152
			}#if end
1152
			}#if end
1153
 
1153
 
1154
		#要執行的系統命令
1154
		#要執行的系統命令
1155
		$paramArray=array();
1155
		$paramArray=array();
1156
		
1156
 
1157
		#設置要用 ssl
1157
		#設置要用 ssl
1158
		$paramArray[]="--ssl-reqd";
1158
		$paramArray[]="--ssl-reqd";
1159
 
1159
 
1160
		#如果為 "levelForCheckSSL" 為 "none"
1160
		#如果為 "levelForCheckSSL" 為 "none"
1161
		if($conf["levelForCheckSSL"]==="none"){
1161
		if($conf["levelForCheckSSL"]==="none"){
1162
		
1162
 
1163
			#設置不用確認ssl符合規範
1163
			#設置不用確認ssl符合規範
1164
			$paramArray[]="-k";
1164
			$paramArray[]="-k";
1165
		
1165
 
1166
			}#if end
1166
			}#if end
1167
 
1167
 
1168
		#設置要設定url
1168
		#設置要設定url
1169
		$paramArray[]="--url";
1169
		$paramArray[]="--url";
1170
		
1170
 
1171
		#設置smtp server
1171
		#設置smtp server
1172
		$paramArray[]=$conf["mailServer"];
1172
		$paramArray[]=$conf["mailServer"];
1173
		
1173
 
1174
		#設置指定使用者名稱
1174
		#設置指定使用者名稱
1175
		$paramArray[]="-u";
1175
		$paramArray[]="-u";
1176
		
1176
 
1177
		#設置使用名稱與密碼
1177
		#設置使用名稱與密碼
1178
		$paramArray[]=$conf["username"].":".$conf["password"];
1178
		$paramArray[]=$conf["username"].":".$conf["password"];
1179
		
1179
 
1180
		#設置要指定寄信來源顯示的名稱
1180
		#設置要指定寄信來源顯示的名稱
1181
		$paramArray[]="--mail-from";
1181
		$paramArray[]="--mail-from";
1182
		
1182
 
1183
		#設置寄信來源顯示的名稱
1183
		#設置寄信來源顯示的名稱
1184
		$paramArray[]=$conf["mailerMailDisplay"];
1184
		$paramArray[]=$conf["mailerMailDisplay"];
1185
		
1185
 
1186
		#有幾個收件人就執行幾次
1186
		#有幾個收件人就執行幾次
1187
		foreach($conf["receiverMail"] as $mailTo){
1187
		foreach($conf["receiverMail"] as $mailTo){
1188
			
1188
 
1189
			#指定收件人的參數
1189
			#指定收件人的參數
1190
			$paramArray[]="--mail-rcpt";
1190
			$paramArray[]="--mail-rcpt";
1191
			
1191
 
1192
			#串接收件人
1192
			#串接收件人
1193
			$paramArray[]=$mailTo;
1193
			$paramArray[]=$mailTo;
1194
			
1194
 
1195
			}#for end
1195
			}#for end
1196
		
1196
 
1197
		#指定mail檔案
1197
		#指定mail檔案
1198
		$paramArray[]="--upload-file";
1198
		$paramArray[]="--upload-file";
1199
		$paramArray[]=$mailFile;
1199
		$paramArray[]=$mailFile;
1200
		
1200
 
1201
		#看過程
1201
		#看過程
1202
		$paramArray[]="-v";
1202
		$paramArray[]="-v";
1203
		
1203
 
1204
		#用curl寄送信件
1204
		#用curl寄送信件
1205
		#函式說明:
1205
		#函式說明:
1206
		#呼叫shell執行系統命令,並取得回傳的內容.
1206
		#呼叫shell執行系統命令,並取得回傳的內容.
1207
		#回傳的結果:
1207
		#回傳的結果:
1208
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1208
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
Line 1229... Line 1229...
1229
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要;"false"代表不要,預設為"false".
1229
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要;"false"代表不要,預設為"false".
1230
		#$conf["useScript"]="";
1230
		#$conf["useScript"]="";
1231
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 ".qbpwcf_tmp/external/callShell/".
1231
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 ".qbpwcf_tmp/external/callShell/".
1232
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
1232
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
1233
		#$conf["fileArgu"],字串,變數__FILE__的內容,預設為當前檔案的路徑與名稱.
1233
		#$conf["fileArgu"],字串,變數__FILE__的內容,預設為當前檔案的路徑與名稱.
1234
		#$conf["fileArgu"]=""; 
1234
		#$conf["fileArgu"]="";
1235
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false".
1235
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false".
1236
		#$conf["external::callShell"]["inBackGround"]="true";
1236
		#$conf["external::callShell"]["inBackGround"]="true";
1237
		#參考資料:
1237
		#參考資料:
1238
		#http://php.net/manual/en/function.exec.php
1238
		#http://php.net/manual/en/function.exec.php
1239
		$external["callShell"]=external::callShell($conf["external::callShell"]);
1239
		$external["callShell"]=external::callShell($conf["external::callShell"]);
1240
		unset($conf["external::callShell"]);
1240
		unset($conf["external::callShell"]);
1241
 
1241
 
1242
		#如果 $external["callShell"] 等於 "false"
1242
		#如果 $external["callShell"] 等於 "false"
1243
		if($external["callShell"]["status"]==="false"){
1243
		if($external["callShell"]["status"]==="false"){
1244
			
1244
 
1245
			#如果 "levelForCheckSSL" 為 "loose"
1245
			#如果 "levelForCheckSSL" 為 "loose"
1246
			if($conf["levelForCheckSSL"]==="loose"){
1246
			if($conf["levelForCheckSSL"]==="loose"){
1247
			
1247
 
1248
				#加上 "-k" 參數,這次不用符合ssl規範
1248
				#加上 "-k" 參數,這次不用符合ssl規範
1249
				$paramArray[]="-k";
1249
				$paramArray[]="-k";
1250
			
1250
 
1251
				#用curl寄送信件
1251
				#用curl寄送信件
1252
				#函式說明:
1252
				#函式說明:
1253
				#呼叫shell執行系統命令,並取得回傳的內容.
1253
				#呼叫shell執行系統命令,並取得回傳的內容.
1254
				#回傳的結果:
1254
				#回傳的結果:
1255
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1255
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
Line 1276... Line 1276...
1276
				#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要;"false"代表不要,預設為"false".
1276
				#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要;"false"代表不要,預設為"false".
1277
				#$conf["useScript"]="";
1277
				#$conf["useScript"]="";
1278
				#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 ".qbpwcf_tmp/external/callShell/".
1278
				#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 ".qbpwcf_tmp/external/callShell/".
1279
				#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
1279
				#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
1280
				#$conf["fileArgu"],字串,變數__FILE__的內容,預設為當前檔案的路徑與名稱.
1280
				#$conf["fileArgu"],字串,變數__FILE__的內容,預設為當前檔案的路徑與名稱.
1281
				#$conf["fileArgu"]=""; 
1281
				#$conf["fileArgu"]="";
1282
				#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false".
1282
				#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false".
1283
				#$conf["external::callShell"]["inBackGround"]="true";
1283
				#$conf["external::callShell"]["inBackGround"]="true";
1284
				#參考資料:
1284
				#參考資料:
1285
				#http://php.net/manual/en/function.exec.php
1285
				#http://php.net/manual/en/function.exec.php
1286
				$external["callShell"]=external::callShell($conf["external::callShell"]);
1286
				$external["callShell"]=external::callShell($conf["external::callShell"]);
1287
				unset($conf["external::callShell"]);
1287
				unset($conf["external::callShell"]);
1288
			
1288
 
1289
				#如果 $external["callShell"] 等於 "false"
1289
				#如果 $external["callShell"] 等於 "false"
1290
				if($external["callShell"]["status"]==="false"){
1290
				if($external["callShell"]["status"]==="false"){
1291
				
1291
 
1292
					#設置錯誤識別
1292
					#設置錯誤識別
1293
					$result["status"]="false";
1293
					$result["status"]="false";
1294
					
1294
 
1295
					#設置錯誤訊息
1295
					#設置錯誤訊息
1296
					$result["error"]=$external["callShell"];
1296
					$result["error"]=$external["callShell"];
1297
					
1297
 
1298
					#回傳結果
1298
					#回傳結果
1299
					return $result;
1299
					return $result;
1300
				
1300
 
1301
					}#if end
1301
					}#if end
1302
				
1302
 
1303
				}#if end
1303
				}#if end
1304
			
1304
 
1305
			#反之
1305
			#反之
1306
			else{
1306
			else{
1307
			
1307
 
1308
				#設置錯誤識別
1308
				#設置錯誤識別
1309
				$result["status"]="false";
1309
				$result["status"]="false";
1310
				
1310
 
1311
				#設置錯誤訊息
1311
				#設置錯誤訊息
1312
				$result["error"]=$external["callShell"];
1312
				$result["error"]=$external["callShell"];
1313
				
1313
 
1314
				#回傳結果
1314
				#回傳結果
1315
				return $result;
1315
				return $result;
1316
				
1316
 
1317
				}#else end`
1317
				}#else end`
1318
			
1318
 
1319
			}#if end
1319
			}#if end
1320
			
1320
 
1321
		#取得較完整的指令
1321
		#取得較完整的指令
1322
		$result["cmd"]=$external["callShell"]["cmd"];
1322
		$result["cmd"]=$external["callShell"]["cmd"];
1323
		
1323
 
1324
		#移除信件檔案
1324
		#移除信件檔案
1325
		#函式說明:
1325
		#函式說明:
1326
		#移除檔案
1326
		#移除檔案
1327
		#回傳結果:
1327
		#回傳結果:
1328
		#$result["status"],"true"代表移除成功,"false"代表移除失敗.
1328
		#$result["status"],"true"代表移除成功,"false"代表移除失敗.
Line 1338... Line 1338...
1338
		#如果移除信件檔案失敗
1338
		#如果移除信件檔案失敗
1339
		if($delMailFile["status"]==="false"){
1339
		if($delMailFile["status"]==="false"){
1340
 
1340
 
1341
			#設置錯誤識別
1341
			#設置錯誤識別
1342
			$result["status"]="false";
1342
			$result["status"]="false";
1343
			
1343
 
1344
			#設置錯誤訊息
1344
			#設置錯誤訊息
1345
			$result["error"]=$delMailFile;
1345
			$result["error"]=$delMailFile;
1346
			
1346
 
1347
			#回傳結果
1347
			#回傳結果
1348
			return $result;
1348
			return $result;
1349
 
1349
 
1350
			}#if end
1350
			}#if end
1351
 
1351
 
1352
		#可以執行到這邊,就表示十之八九寄信成功了
1352
		#可以執行到這邊,就表示十之八九寄信成功了
1353
		$result["status"]="true";
1353
		$result["status"]="true";
1354
		
1354
 
1355
		#回傳結果
1355
		#回傳結果
1356
		return $result;
1356
		return $result;
1357
 
1357
 
1358
		}#function curlSmtp end
1358
		}#function curlSmtp end
1359
	
1359
 
1360
	/*
1360
	/*
1361
	#函式說明:
1361
	#函式說明:
1362
	#使用 linux 的 curl 指令來透過SMTP伺服器寄大量不同內容的信件.
1362
	#使用 linux 的 curl 指令來透過SMTP伺服器寄大量不同內容的信件.
1363
	#回傳結果:
1363
	#回傳結果:
1364
	#$result["status"],寄信的情況,若爲"true",則十之八九沒有問題.
1364
	#$result["status"],寄信的情況,若爲"true",則十之八九沒有問題.
Line 1407... Line 1407...
1407
	#無.
1407
	#無.
1408
	#備註:
1408
	#備註:
1409
	#無.
1409
	#無.
1410
	*/
1410
	*/
1411
	public static function multiCurlSmtp(&$conf){
1411
	public static function multiCurlSmtp(&$conf){
1412
		
1412
 
1413
		#初始化要回傳的結果
1413
		#初始化要回傳的結果
1414
		$result=array();
1414
		$result=array();
1415
 
1415
 
1416
		#儲存當前執行的函數
1416
		#儲存當前執行的函數
1417
		$result["function"]=__FUNCTION__;
1417
		$result["function"]=__FUNCTION__;
1418
 
1418
 
1419
		#如果 $conf 不為陣列
1419
		#如果 $conf 不為陣列
1420
		if(gettype($conf)!="array"){
1420
		if(gettype($conf)!="array"){
1421
			
1421
 
1422
			#設置執行失敗
1422
			#設置執行失敗
1423
			$result["status"]="false";
1423
			$result["status"]="false";
1424
			
1424
 
1425
			#設置執行錯誤訊息
1425
			#設置執行錯誤訊息
1426
			$result["error"][]="\$conf變數須為陣列形態";
1426
			$result["error"][]="\$conf變數須為陣列形態";
1427
 
1427
 
1428
			#如果傳入的參數為 null
1428
			#如果傳入的參數為 null
1429
			if($conf==null){
1429
			if($conf==null){
1430
				
1430
 
1431
				#設置執行錯誤訊息
1431
				#設置執行錯誤訊息
1432
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
1432
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
1433
				
1433
 
1434
				}#if end
1434
				}#if end
1435
 
1435
 
1436
			#回傳結果
1436
			#回傳結果
1437
			return $result;
1437
			return $result;
1438
	
1438
 
1439
			}#if end
1439
			}#if end
1440
	
1440
 
1441
		#檢查參數
1441
		#檢查參數
1442
		#函式說明:
1442
		#函式說明:
1443
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
1443
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
1444
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1444
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1445
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
1445
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
Line 1454... Line 1454...
1454
		#必填寫的參數:
1454
		#必填寫的參數:
1455
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
1455
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
1456
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
1456
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
1457
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
1457
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
1458
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("username","password","receiverMail","subject","plainBody","htmlBody","fileArgu");
1458
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("username","password","receiverMail","subject","plainBody","htmlBody","fileArgu");
1459
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); 
1459
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
1460
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","array","array","array","array","string");
1460
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","array","array","array","array","string");
1461
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
1461
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
1462
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
1462
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
1463
		#可以省略的參數:
1463
		#可以省略的參數:
1464
		#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
1464
		#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
1465
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
1465
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
1466
		#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
1466
		#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
1467
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("attachment","attachmentName","attachmentMimeType","mailServer","mailerMailDisplay","mailerNameDisplay","receiverMailDisplay","receiverNameDisplay","insecure","usernameOnly");
1467
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("attachment","attachmentName","attachmentMimeType","mailServer","mailerMailDisplay","mailerNameDisplay","receiverMailDisplay","receiverNameDisplay","insecure","usernameOnly");
1468
		#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double"); 
1468
		#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
1469
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array","array","array","string","string","string","array","array","string","string");
1469
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array","array","array","string","string","string","array","array","string","string");
1470
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
1470
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
1471
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,null,null,"smtps://smtp.gmail.com:465","\$conf[\"username\"]","\$conf[\"username\"]","\$conf[\"receiverMail\"]","\$conf[\"receiverMail\"]","false","false");
1471
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,null,null,"smtps://smtp.gmail.com:465","\$conf[\"username\"]","\$conf[\"username\"]","\$conf[\"receiverMail\"]","\$conf[\"receiverMail\"]","false","false");
1472
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
1472
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
1473
		$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("subject","plainBody","htmlBody","receiverMail","receiverMailDisplay","receiverNameDisplay");
1473
		$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("subject","plainBody","htmlBody","receiverMail","receiverMailDisplay","receiverNameDisplay");
1474
		#參考資料來源:
1474
		#參考資料來源:
1475
		#array_keys=>http://php.net/manual/en/function.array-keys.php
1475
		#array_keys=>http://php.net/manual/en/function.array-keys.php
1476
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
1476
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
1477
		unset($conf["variableCheck::checkArguments"]);
1477
		unset($conf["variableCheck::checkArguments"]);
1478
	
1478
 
1479
		#如果檢查失敗
1479
		#如果檢查失敗
1480
		if($checkArguments["status"]=="false"){
1480
		if($checkArguments["status"]=="false"){
1481
			
1481
 
1482
			#設置錯誤識別
1482
			#設置錯誤識別
1483
			$result["status"]="false";
1483
			$result["status"]="false";
1484
			
1484
 
1485
			#設置錯誤訊息
1485
			#設置錯誤訊息
1486
			$result["error"]=$checkArguments;
1486
			$result["error"]=$checkArguments;
1487
			
1487
 
1488
			#回傳結果
1488
			#回傳結果
1489
			return $result;
1489
			return $result;
1490
			
1490
 
1491
			}#if end
1491
			}#if end
1492
	
1492
 
1493
		#如果檢查不通過
1493
		#如果檢查不通過
1494
		if($checkArguments["passed"]=="false"){
1494
		if($checkArguments["passed"]=="false"){
1495
			
1495
 
1496
			#設置錯誤識別
1496
			#設置錯誤識別
1497
			$result["status"]="false";
1497
			$result["status"]="false";
1498
			
1498
 
1499
			#設置錯誤訊息
1499
			#設置錯誤訊息
1500
			$result["error"]=$checkArguments;
1500
			$result["error"]=$checkArguments;
1501
			
1501
 
1502
			#回傳結果
1502
			#回傳結果
1503
			return $result;
1503
			return $result;
1504
			
1504
 
1505
			}#if end
1505
			}#if end
1506
	
1506
 
1507
		#檢查 .curlSmtp 資料夾是否存在
1507
		#檢查 .curlSmtp 資料夾是否存在
1508
		#函式說明:檢查多個檔案是否存在
1508
		#函式說明:檢查多個檔案是否存在
1509
		#回傳的結果:
1509
		#回傳的結果:
1510
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
1510
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
1511
		#$result["error"],錯誤訊息陣列.
1511
		#$result["error"],錯誤訊息陣列.
Line 1519... Line 1519...
1519
		#參考資料來源:
1519
		#參考資料來源:
1520
		#http://php.net/manual/en/function.file-exists.php
1520
		#http://php.net/manual/en/function.file-exists.php
1521
		#http://php.net/manual/en/control-structures.foreach.php
1521
		#http://php.net/manual/en/control-structures.foreach.php
1522
		$checkMutiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
1522
		$checkMutiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
1523
		unset($conf["fileAccess::checkMultiFileExist"]);
1523
		unset($conf["fileAccess::checkMultiFileExist"]);
1524
		
1524
 
1525
		#如果檢查檔案失敗
1525
		#如果檢查檔案失敗
1526
		if($checkMutiFileExist["status"]=="false"){
1526
		if($checkMutiFileExist["status"]=="false"){
1527
			
1527
 
1528
			#設置錯誤識別
1528
			#設置錯誤識別
1529
			$result["status"]="false";
1529
			$result["status"]="false";
1530
			
1530
 
1531
			#設置錯誤訊息
1531
			#設置錯誤訊息
1532
			$result["error"]=$checkMutiFileExist;
1532
			$result["error"]=$checkMutiFileExist;
1533
			
1533
 
1534
			#回傳結果
1534
			#回傳結果
1535
			return $result;
1535
			return $result;
1536
			
1536
 
1537
			}#if end
1537
			}#if end
1538
 
1538
 
1539
		#如果該資料夾不存在
1539
		#如果該資料夾不存在
1540
		if($checkMutiFileExist["varExist"][0]=="false"){
1540
		if($checkMutiFileExist["varExist"][0]=="false"){
1541
 
1541
 
Line 1550... Line 1550...
1550
			$conf["fileAccess::createFolderAfterCheck"]["fileArgu"]=$conf["fileArgu"];
1550
			$conf["fileAccess::createFolderAfterCheck"]["fileArgu"]=$conf["fileArgu"];
1551
			#可省略參數:
1551
			#可省略參數:
1552
			#$conf["fileAccess::createFolderAfterCheck"]["dirPermission"]="";#新建資料夾的權限設定,預設爲0770,亦即擁有者,同群組者可以讀,寫,存取,其他人僅能存取.
1552
			#$conf["fileAccess::createFolderAfterCheck"]["dirPermission"]="";#新建資料夾的權限設定,預設爲0770,亦即擁有者,同群組者可以讀,寫,存取,其他人僅能存取.
1553
			$createFolderAfterCheck=fileAccess::createFolderAfterCheck($conf["fileAccess::createFolderAfterCheck"]);
1553
			$createFolderAfterCheck=fileAccess::createFolderAfterCheck($conf["fileAccess::createFolderAfterCheck"]);
1554
			unset($conf["fileAccess::createFolderAfterCheck"]);
1554
			unset($conf["fileAccess::createFolderAfterCheck"]);
1555
			
1555
 
1556
			#如果 建立資料夾失敗
1556
			#如果 建立資料夾失敗
1557
			if($createFolderAfterCheck["status"]=="false"){
1557
			if($createFolderAfterCheck["status"]=="false"){
1558
 
1558
 
1559
				#設置錯誤識別
1559
				#設置錯誤識別
1560
				$result["status"]="false";
1560
				$result["status"]="false";
Line 1566... Line 1566...
1566
				return $result;
1566
				return $result;
1567
 
1567
 
1568
				}#if end
1568
				}#if end
1569
 
1569
 
1570
			}#if end
1570
			}#if end
1571
		
1571
 
1572
		#初始化寄信的command
1572
		#初始化寄信的command
1573
		#$mailCmd="";
1573
		#$mailCmd="";
1574
		
1574
 
1575
		#初始化寄信的指令
1575
		#初始化寄信的指令
1576
		$mailCmdArray=array();		
1576
		$mailCmdArray=array();
1577
			
1577
 
1578
		#初始化移除信件檔案的指令
1578
		#初始化移除信件檔案的指令
1579
		$delMailFileCmd=array();
1579
		$delMailFileCmd=array();
1580
		
1580
 
1581
		#取得 $systemTime	
1581
		#取得 $systemTime
1582
		$systemTime=time::getMicrotime();
1582
		$systemTime=time::getMicrotime();
1583
 
1583
 
1584
		#要傳送的信件資訊
1584
		#要傳送的信件資訊
1585
		$fromInfo="From: ".$conf["mailerNameDisplay"]." <".$conf["mailerMailDisplay"].">\r\n";
1585
		$fromInfo="From: ".$conf["mailerNameDisplay"]." <".$conf["mailerMailDisplay"].">\r\n";
1586
		
1586
 
1587
		#初始化信件的 header
1587
		#初始化信件的 header
1588
		$mailFileHeader="";
1588
		$mailFileHeader="";
1589
		
1589
 
1590
		#依據 $conf["receiverMail"] 的數量
1590
		#依據 $conf["receiverMail"] 的數量
1591
		for($i=0;$i<count($conf["receiverMail"]);$i++){
1591
		for($i=0;$i<count($conf["receiverMail"]);$i++){
1592
			
1592
 
1593
			#串接寄件人的資訊
1593
			#串接寄件人的資訊
1594
			$mailFileHeader=$mailFileHeader.$fromInfo;
1594
			$mailFileHeader=$mailFileHeader.$fromInfo;
1595
				
1595
 
1596
			#如果第$i筆信件的收件人陣列不存在
1596
			#如果第$i筆信件的收件人陣列不存在
1597
			if(!isset($conf["receiverMail"][$i])){
1597
			if(!isset($conf["receiverMail"][$i])){
1598
				
1598
 
1599
				#設置執行不正常
1599
				#設置執行不正常
1600
				$result["status"]="false";
1600
				$result["status"]="false";
1601
				
1601
 
1602
				#設置錯誤訊息
1602
				#設置錯誤訊息
1603
				$result["error"][]="第".($i+1)."筆收件人陣列不存在";
1603
				$result["error"][]="第".($i+1)."筆收件人陣列不存在";
1604
				
1604
 
1605
				#回傳結果
1605
				#回傳結果
1606
				return $result;
1606
				return $result;
1607
				
1607
 
1608
				}#if end
1608
				}#if end
1609
 
1609
 
1610
			#反之存在但形態不為陣列
1610
			#反之存在但形態不為陣列
1611
			if(gettype($conf["receiverMail"][$i])!="array"){
1611
			if(gettype($conf["receiverMail"][$i])!="array"){
1612
				
1612
 
1613
				#設置執行不正常
1613
				#設置執行不正常
1614
				$result["status"]="false";
1614
				$result["status"]="false";
1615
				
1615
 
1616
				#設置錯誤訊息
1616
				#設置錯誤訊息
1617
				$result["error"][]="第".($i+1)."筆收件人陣列形態不正確";
1617
				$result["error"][]="第".($i+1)."筆收件人陣列形態不正確";
1618
				
1618
 
1619
				#回傳結果
1619
				#回傳結果
1620
				return $result;
1620
				return $result;
1621
				
1621
 
1622
				}#if end	
1622
				}#if end
1623
						
1623
 
1624
			#如果第$i筆信件的收件人名稱不存在
1624
			#如果第$i筆信件的收件人名稱不存在
1625
			if(!isset($conf["receiverNameDisplay"][$i])){
1625
			if(!isset($conf["receiverNameDisplay"][$i])){
1626
								
1626
 
1627
				#設為第$i筆信件的收件人陣列
1627
				#設為第$i筆信件的收件人陣列
1628
				$conf["receiverNameDisplay"][$i]=$conf["receiverMail"][$i];
1628
				$conf["receiverNameDisplay"][$i]=$conf["receiverMail"][$i];
1629
								
1629
 
1630
				}#if end
1630
				}#if end
1631
				
1631
 
1632
			#第$i筆信件收件人名稱陣列的第一個元素不存在
1632
			#第$i筆信件收件人名稱陣列的第一個元素不存在
1633
			else if(!isset($conf["receiverNameDisplay"][$i][0])){
1633
			else if(!isset($conf["receiverNameDisplay"][$i][0])){
1634
				
1634
 
1635
				#設置執行不正常
1635
				#設置執行不正常
1636
				$result["status"]="false";
1636
				$result["status"]="false";
1637
				
1637
 
1638
				#設置錯誤訊息
1638
				#設置錯誤訊息
1639
				$result["error"][]="第".($i+1)."筆收件人名稱陣列的第一個收件人名稱不存在";
1639
				$result["error"][]="第".($i+1)."筆收件人名稱陣列的第一個收件人名稱不存在";
1640
				
1640
 
1641
				#回傳結果
1641
				#回傳結果
1642
				return $result;
1642
				return $result;
1643
				
1643
 
1644
				}#if end
1644
				}#if end
1645
			
1645
 
1646
			#如果第$i筆信件的收件人信箱名稱不存在
1646
			#如果第$i筆信件的收件人信箱名稱不存在
1647
			if(!isset($conf["receiverMailDisplay"][$i])){
1647
			if(!isset($conf["receiverMailDisplay"][$i])){
1648
				
1648
 
1649
				#設為第$i筆信件的收件人陣列
1649
				#設為第$i筆信件的收件人陣列
1650
				$conf["receiverMailDisplay"][$i]=$conf["receiverMail"][$i];
1650
				$conf["receiverMailDisplay"][$i]=$conf["receiverMail"][$i];
1651
								
1651
 
1652
				}#if end
1652
				}#if end
1653
				
1653
 
1654
			#第$i筆信件收件人信箱名稱陣列的第一個元素不存在
1654
			#第$i筆信件收件人信箱名稱陣列的第一個元素不存在
1655
			else if(!isset($conf["receiverNameDisplay"][$i][0])){
1655
			else if(!isset($conf["receiverNameDisplay"][$i][0])){
1656
				
1656
 
1657
				#設置執行不正常
1657
				#設置執行不正常
1658
				$result["status"]="false";
1658
				$result["status"]="false";
1659
				
1659
 
1660
				#設置錯誤訊息
1660
				#設置錯誤訊息
1661
				$result["error"][]="第".($i+1)."筆收件人信箱名稱陣列的第一個收件人信箱名稱不存在";
1661
				$result["error"][]="第".($i+1)."筆收件人信箱名稱陣列的第一個收件人信箱名稱不存在";
1662
				
1662
 
1663
				#回傳結果
1663
				#回傳結果
1664
				return $result;
1664
				return $result;
1665
				
1665
 
1666
				}#if end						
1666
				}#if end
1667
								
1667
 
1668
			#第一個人為主要收件人
1668
			#第一個人為主要收件人
1669
			$mailFileHeader=$mailFileHeader."To: ".$conf["receiverNameDisplay"][$i][0]." "."<".$conf["receiverMailDisplay"][$i][0].">\r\n";			
1669
			$mailFileHeader=$mailFileHeader."To: ".$conf["receiverNameDisplay"][$i][0]." "."<".$conf["receiverMailDisplay"][$i][0].">\r\n";
1670
			
1670
 
1671
			#如果有其餘收件人
1671
			#如果有其餘收件人
1672
			if(count($conf["receiverNameDisplay"][$i])>1){
1672
			if(count($conf["receiverNameDisplay"][$i])>1){
1673
				
1673
 
1674
				#副本寄送處的資訊開始
1674
				#副本寄送處的資訊開始
1675
				$mailFileHeader=$mailFileHeader."Cc: ";
1675
				$mailFileHeader=$mailFileHeader."Cc: ";
1676
				
1676
 
1677
				}#if end
1677
				}#if end
1678
			
1678
 
1679
			#針對其餘收件人的地址
1679
			#針對其餘收件人的地址
1680
			for($j=1;$j<count($conf["receiverNameDisplay"][$i]);$j++){
1680
			for($j=1;$j<count($conf["receiverNameDisplay"][$i]);$j++){
1681
				
1681
 
1682
				#如果不是最後一筆
1682
				#如果不是最後一筆
1683
				if($j!=count($conf["receiverNameDisplay"][$i])-1){
1683
				if($j!=count($conf["receiverNameDisplay"][$i])-1){
1684
					
1684
 
1685
					#串接並加上逗號
1685
					#串接並加上逗號
1686
					$mailFileHeader=$mailFileHeader.$conf["receiverNameDisplay"][$i][$j]." <".$conf["receiverMailDisplay"][$i][$j].">,";
1686
					$mailFileHeader=$mailFileHeader.$conf["receiverNameDisplay"][$i][$j]." <".$conf["receiverMailDisplay"][$i][$j].">,";
1687
					
1687
 
1688
					}#if end
1688
					}#if end
1689
				
1689
 
1690
				#反之是最後一筆
1690
				#反之是最後一筆
1691
				else{
1691
				else{
1692
					
1692
 
1693
					#串接並接上換行符號
1693
					#串接並接上換行符號
1694
					$mailFileHeader=$mailFileHeader.$conf["receiverNameDisplay"][$i][$j]." <".$conf["receiverMailDisplay"][$i][$j].">\r\n";
1694
					$mailFileHeader=$mailFileHeader.$conf["receiverNameDisplay"][$i][$j]." <".$conf["receiverMailDisplay"][$i][$j].">\r\n";
1695
					
1695
 
1696
					}#else end				
1696
					}#else end
1697
				
1697
 
1698
				}#for end
1698
				}#for end
1699
			
1699
 
1700
			#設置信件標題
1700
			#設置信件標題
1701
			$mailFileHeader=$mailFileHeader."Subject: ".$conf["subject"][$i]."\r\n";
1701
			$mailFileHeader=$mailFileHeader."Subject: ".$conf["subject"][$i]."\r\n";
1702
		
1702
 
1703
			#設置 MIME-Version
1703
			#設置 MIME-Version
1704
			$mailFileHeader=$mailFileHeader."MIME-Version: 1.0\r\n";
1704
			$mailFileHeader=$mailFileHeader."MIME-Version: 1.0\r\n";
1705
			
1705
 
1706
			#初始化信件本文
1706
			#初始化信件本文
1707
			$mailFileContent="";
1707
			$mailFileContent="";
1708
				
1708
 
1709
			#設置信件本文(純文字與html兩種)				
1709
			#設置信件本文(純文字與html兩種)
1710
			$mailFileContent=$mailFileContent."--001a11c30ce8aec3550533bfa9ab\r\n";
1710
			$mailFileContent=$mailFileContent."--001a11c30ce8aec3550533bfa9ab\r\n";
1711
			$mailFileContent=$mailFileContent."Content-Type: multipart/alternative; boundary=001a11c30ce8aec3480533bfa9a9\r\n";
1711
			$mailFileContent=$mailFileContent."Content-Type: multipart/alternative; boundary=001a11c30ce8aec3480533bfa9a9\r\n";
1712
			$mailFileContent=$mailFileContent."\r\n";
1712
			$mailFileContent=$mailFileContent."\r\n";
1713
			$mailFileContent=$mailFileContent."--001a11c30ce8aec3480533bfa9a9\r\n";
1713
			$mailFileContent=$mailFileContent."--001a11c30ce8aec3480533bfa9a9\r\n";
1714
			$mailFileContent=$mailFileContent."Content-Type: text/plain; charset=UTF-8\r\n";
1714
			$mailFileContent=$mailFileContent."Content-Type: text/plain; charset=UTF-8\r\n";
Line 1719... Line 1719...
1719
			$mailFileContent=$mailFileContent."Content-Type: text/html; charset=UTF-8\r\n";
1719
			$mailFileContent=$mailFileContent."Content-Type: text/html; charset=UTF-8\r\n";
1720
			$mailFileContent=$mailFileContent."\r\n";
1720
			$mailFileContent=$mailFileContent."\r\n";
1721
			$mailFileContent=$mailFileContent.$conf["htmlBody"][$i]."\r\n";
1721
			$mailFileContent=$mailFileContent.$conf["htmlBody"][$i]."\r\n";
1722
			$mailFileContent=$mailFileContent."\r\n";
1722
			$mailFileContent=$mailFileContent."\r\n";
1723
			$mailFileContent=$mailFileContent."--001a11c30ce8aec3480533bfa9a9--\r\n";
1723
			$mailFileContent=$mailFileContent."--001a11c30ce8aec3480533bfa9a9--\r\n";
1724
			
1724
 
1725
			#如果有設定要上傳附件
1725
			#如果有設定要上傳附件
1726
			if(isset($conf["attachment"])){
1726
			if(isset($conf["attachment"])){
1727
				
1727
 
1728
				#如果第 $i+1 封信件有指定 附件
1728
				#如果第 $i+1 封信件有指定 附件
1729
				if(isset($conf["attachment"][$i])){
1729
				if(isset($conf["attachment"][$i])){
1730
					
1730
 
1731
					#如果類型正確
1731
					#如果類型正確
1732
					if(gettype($conf["attachment"][$i])=="array"){
1732
					if(gettype($conf["attachment"][$i])=="array"){
1733
						
1733
 
1734
						#依據每個附件
1734
						#依據每個附件
1735
						for($j=0;$j<count($conf["attachment"][$i]);$j++){
1735
						for($j=0;$j<count($conf["attachment"][$i]);$j++){
1736
							
1736
 
1737
							#初始化寄送附件的語法
1737
							#初始化寄送附件的語法
1738
							$attachment="";
1738
							$attachment="";
1739
							
1739
 
1740
							#確認目標檔案是否存在 #函式說明:檢查多個檔案是否存在 #回傳的結果: 
1740
							#確認目標檔案是否存在 #函式說明:檢查多個檔案是否存在 #回傳的結果:
1741
							#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常. 
1741
							#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
1742
							#$result["error"],錯誤訊息陣列. 
1742
							#$result["error"],錯誤訊息陣列.
1743
							#$resutl["function"],當前執行的涵式名稱. 
1743
							#$resutl["function"],當前執行的涵式名稱.
1744
							#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在. 
1744
							#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
1745
							#$result["varName"][$i],爲第$i個資料夾或檔案的名稱。 
1745
							#$result["varName"][$i],爲第$i個資料夾或檔案的名稱。
1746
							#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。 
1746
							#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
1747
							#必填參數: 
1747
							#必填參數:
1748
							$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"]; 
1748
							$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
1749
							$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($conf["attachment"][$i][$j]);#要檢查書否存在的檔案有哪些,須爲一維陣列數值。 
1749
							$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($conf["attachment"][$i][$j]);#要檢查書否存在的檔案有哪些,須爲一維陣列數值。
1750
							#參考資料來源: 
1750
							#參考資料來源:
1751
							#http://php.net/manual/en/function.file-exists.php 
1751
							#http://php.net/manual/en/function.file-exists.php
1752
							#http://php.net/manual/en/control-structures.foreach.php 
1752
							#http://php.net/manual/en/control-structures.foreach.php
1753
							$checkMutiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]); 
1753
							$checkMutiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
1754
							unset($conf["fileAccess::checkMultiFileExist"]);
1754
							unset($conf["fileAccess::checkMultiFileExist"]);
1755
								
1755
 
1756
							#如果檢查失敗
1756
							#如果檢查失敗
1757
							if($checkMutiFileExist["status"]=="false"){
1757
							if($checkMutiFileExist["status"]=="false"){
1758
								
1758
 
1759
								#設置錯誤識別
1759
								#設置錯誤識別
1760
								$result["status"]="false";
1760
								$result["status"]="false";
1761
 
1761
 
1762
								#設置錯誤資訊
1762
								#設置錯誤資訊
1763
								$result["error"]=$checkMutiFileExist;
1763
								$result["error"]=$checkMutiFileExist;
1764
 
1764
 
1765
								#回傳結果
1765
								#回傳結果
1766
								return $result;
1766
								return $result;
1767
								
1767
 
1768
								}#if end
1768
								}#if end
1769
								
1769
 
1770
							#如果檔案不存在
1770
							#如果檔案不存在
1771
							if($checkMutiFileExist["varExist"][0]=="false"){
1771
							if($checkMutiFileExist["varExist"][0]=="false"){
1772
								
1772
 
1773
								#設置錯誤識別
1773
								#設置錯誤識別
1774
								$result["status"]="false";
1774
								$result["status"]="false";
1775
 
1775
 
1776
								#設置錯誤資訊
1776
								#設置錯誤資訊
1777
								$result["error"]=$checkMutiFileExist;
1777
								$result["error"]=$checkMutiFileExist;
1778
 
1778
 
1779
								#回傳結果
1779
								#回傳結果
1780
								return $result;
1780
								return $result;
1781
								
1781
 
1782
								}#if end
1782
								}#if end
1783
								
1783
 
1784
							#如果是第一個附件
1784
							#如果是第一個附件
1785
							if($j==0){
1785
							if($j==0){
1786
								
1786
 
1787
								#在前面加上 multipart/mixed 的 boundary
1787
								#在前面加上 multipart/mixed 的 boundary
1788
								$mailFileContent="Content-Type: multipart/mixed; boundary=001a11c30ce8aec3550533bfa9ab\r\n\r\n".$mailFileContent;
1788
								$mailFileContent="Content-Type: multipart/mixed; boundary=001a11c30ce8aec3550533bfa9ab\r\n\r\n".$mailFileContent;
1789
								
1789
 
1790
								}#if end
1790
								}#if end
1791
								
1791
 
1792
							#如果 $conf["attachmentName"][$i] 不存在
1792
							#如果 $conf["attachmentName"][$i] 不存在
1793
							if(!isset($conf["attachmentName"][$i])){
1793
							if(!isset($conf["attachmentName"][$i])){
1794
								
1794
 
1795
								#涵是說明:
1795
								#涵是說明:
1796
								#取得檔案路徑字串的路徑與檔案的名稱與檔案副檔名
1796
								#取得檔案路徑字串的路徑與檔案的名稱與檔案副檔名
1797
								#回傳的結果:
1797
								#回傳的結果:
1798
								#$result["status"],執行是否正常,"true"正常,"false"代表不正常.
1798
								#$result["status"],執行是否正常,"true"正常,"false"代表不正常.
1799
								#$result["error"],錯誤訊息.
1799
								#$result["error"],錯誤訊息.
Line 1808... Line 1808...
1808
								$conf["fileAccess::getFileAddressAndNameAndFileExtention"]["fileAddressAndName"]=$conf["attachment"][$i][$j];
1808
								$conf["fileAccess::getFileAddressAndNameAndFileExtention"]["fileAddressAndName"]=$conf["attachment"][$i][$j];
1809
								#可省略的參數:
1809
								#可省略的參數:
1810
								#無.
1810
								#無.
1811
								$getFileAddressAndNameAndFileExtention=fileAccess::getFileAddressAndNameAndFileExtention($conf["fileAccess::getFileAddressAndNameAndFileExtention"]);
1811
								$getFileAddressAndNameAndFileExtention=fileAccess::getFileAddressAndNameAndFileExtention($conf["fileAccess::getFileAddressAndNameAndFileExtention"]);
1812
								unset($conf["fileAccess::getFileAddressAndNameAndFileExtention"]);
1812
								unset($conf["fileAccess::getFileAddressAndNameAndFileExtention"]);
1813
										
1813
 
1814
								#如果解析檔案資訊失敗		
1814
								#如果解析檔案資訊失敗
1815
								if($getFileAddressAndNameAndFileExtention["status"]=="false"){
1815
								if($getFileAddressAndNameAndFileExtention["status"]=="false"){
1816
									
1816
 
1817
									#設置錯誤識別
1817
									#設置錯誤識別
1818
									$result["status"]="false";
1818
									$result["status"]="false";
1819
 
1819
 
1820
									#設置錯誤資訊
1820
									#設置錯誤資訊
1821
									$result["error"]=$getFileAddressAndNameAndFileExtention;
1821
									$result["error"]=$getFileAddressAndNameAndFileExtention;
1822
 
1822
 
1823
									#回傳結果
1823
									#回傳結果
1824
									return $result;
1824
									return $result;
1825
									
1825
 
1826
									}#if end			
1826
									}#if end
1827
												
1827
 
1828
								#設定附件名稱
1828
								#設定附件名稱
1829
								$conf["attachmentName"][$i][$j]=$getFileAddressAndNameAndFileExtention["fullFileName"];
1829
								$conf["attachmentName"][$i][$j]=$getFileAddressAndNameAndFileExtention["fullFileName"];
1830
								
1830
 
1831
								}#if end
1831
								}#if end
1832
								
1832
 
1833
							#反之如果 $conf["attachmentName"][$i][$j] 不存在
1833
							#反之如果 $conf["attachmentName"][$i][$j] 不存在
1834
							else if(!isset($conf["attachmentName"][$i][$j])){
1834
							else if(!isset($conf["attachmentName"][$i][$j])){
1835
								
1835
 
1836
								#涵是說明:
1836
								#涵是說明:
1837
								#取得檔案路徑字串的路徑與檔案的名稱與檔案副檔名
1837
								#取得檔案路徑字串的路徑與檔案的名稱與檔案副檔名
1838
								#回傳的結果:
1838
								#回傳的結果:
1839
								#$result["status"],執行是否正常,"true"正常,"false"代表不正常.
1839
								#$result["status"],執行是否正常,"true"正常,"false"代表不正常.
1840
								#$result["error"],錯誤訊息.
1840
								#$result["error"],錯誤訊息.
Line 1849... Line 1849...
1849
								$conf["fileAccess::getFileAddressAndNameAndFileExtention"]["fileAddressAndName"]=$conf["attachment"][$i][$j];
1849
								$conf["fileAccess::getFileAddressAndNameAndFileExtention"]["fileAddressAndName"]=$conf["attachment"][$i][$j];
1850
								#可省略的參數:
1850
								#可省略的參數:
1851
								#無.
1851
								#無.
1852
								$getFileAddressAndNameAndFileExtention=fileAccess::getFileAddressAndNameAndFileExtention($conf["fileAccess::getFileAddressAndNameAndFileExtention"]);
1852
								$getFileAddressAndNameAndFileExtention=fileAccess::getFileAddressAndNameAndFileExtention($conf["fileAccess::getFileAddressAndNameAndFileExtention"]);
1853
								unset($conf["fileAccess::getFileAddressAndNameAndFileExtention"]);
1853
								unset($conf["fileAccess::getFileAddressAndNameAndFileExtention"]);
1854
										
1854
 
1855
								#如果解析檔案資訊失敗		
1855
								#如果解析檔案資訊失敗
1856
								if($getFileAddressAndNameAndFileExtention["status"]=="false"){
1856
								if($getFileAddressAndNameAndFileExtention["status"]=="false"){
1857
									
1857
 
1858
									#設置錯誤識別
1858
									#設置錯誤識別
1859
									$result["status"]="false";
1859
									$result["status"]="false";
1860
 
1860
 
1861
									#設置錯誤資訊
1861
									#設置錯誤資訊
1862
									$result["error"]=$getFileAddressAndNameAndFileExtention;
1862
									$result["error"]=$getFileAddressAndNameAndFileExtention;
1863
 
1863
 
1864
									#回傳結果
1864
									#回傳結果
1865
									return $result;
1865
									return $result;
1866
									
1866
 
1867
									}#if end			
1867
									}#if end
1868
												
1868
 
1869
								#設定附件名稱
1869
								#設定附件名稱
1870
								$conf["attachmentName"][$i][$j]=$getFileAddressAndNameAndFileExtention["fullFileName"];
1870
								$conf["attachmentName"][$i][$j]=$getFileAddressAndNameAndFileExtention["fullFileName"];
1871
								
1871
 
1872
								}#if end
1872
								}#if end
1873
								
1873
 
1874
							#如果 $conf["attachmentMimeType"][$i][$j] 不存在
1874
							#如果 $conf["attachmentMimeType"][$i][$j] 不存在
1875
							if(!isset($conf["attachmentMimeType"][$i])){
1875
							if(!isset($conf["attachmentMimeType"][$i])){
1876
								
1876
 
1877
								#設定檔案類型
1877
								#設定檔案類型
1878
								$conf["attachmentMimeType"][$i][$j]="application/*";
1878
								$conf["attachmentMimeType"][$i][$j]="application/*";
1879
																	
-
 
-
 
1879
 
1880
								}#if end	
1880
								}#if end
1881
								
1881
 
1882
							#反之如果 $conf["attachmentMimeType"][$i][$j] 不存在	
1882
							#反之如果 $conf["attachmentMimeType"][$i][$j] 不存在
1883
							else if(!isset($conf["attachmentMimeType"][$i][$j])){
1883
							else if(!isset($conf["attachmentMimeType"][$i][$j])){
1884
								
1884
 
1885
								$conf["attachmentMimeType"][$i][$j]="application/*";
1885
								$conf["attachmentMimeType"][$i][$j]="application/*";
1886
								
1886
 
1887
								}#if end
1887
								}#if end
1888
							
1888
 
1889
							#加上寄送附件的語法
1889
							#加上寄送附件的語法
1890
							$attachment=$attachment."--001a11c30ce8aec3550533bfa9ab\r\n";
1890
							$attachment=$attachment."--001a11c30ce8aec3550533bfa9ab\r\n";
1891
							$attachment=$attachment."Content-Type: ".$conf["attachmentMimeType"][$i][$j]."; name=".$conf["attachmentName"][$i][$j]."\r\n";
1891
							$attachment=$attachment."Content-Type: ".$conf["attachmentMimeType"][$i][$j]."; name=".$conf["attachmentName"][$i][$j]."\r\n";
1892
							$attachment=$attachment."Content-Disposition: attachment; filename=".$conf["attachmentName"][$i][$j]."\r\n";
1892
							$attachment=$attachment."Content-Disposition: attachment; filename=".$conf["attachmentName"][$i][$j]."\r\n";
1893
							$attachment=$attachment."Content-Transfer-Encoding: base64\r\n";			
1893
							$attachment=$attachment."Content-Transfer-Encoding: base64\r\n";
1894
							$attachment=$attachment."X-Attachment-Id: f_io1ikfii".$i."_".$j."\r\n";
1894
							$attachment=$attachment."X-Attachment-Id: f_io1ikfii".$i."_".$j."\r\n";
1895
								
1895
 
1896
							#將檔案用base64加密					
1896
							#將檔案用base64加密
1897
							$base64fileStr=base64_encode(file_get_contents($conf["attachment"][$i][$j]));
1897
							$base64fileStr=base64_encode(file_get_contents($conf["attachment"][$i][$j]));
1898
							
1898
 
1899
							#依據規定,每列不得大於70的字元
1899
							#依據規定,每列不得大於70的字元
1900
							$wordwrapedFileStr=wordwrap($base64fileStr,70,"\r\n",true);
1900
							$wordwrapedFileStr=wordwrap($base64fileStr,70,"\r\n",true);
1901
							
1901
 
1902
							#斷行後附加檔案字串
1902
							#斷行後附加檔案字串
1903
							$attachment=$attachment."\r\n".$wordwrapedFileStr."\r\n";	
1903
							$attachment=$attachment."\r\n".$wordwrapedFileStr."\r\n";
1904
								
1904
 
1905
							#如果是最後一個附件
1905
							#如果是最後一個附件
1906
							if($j==count($conf["attachment"][$i])-1){
1906
							if($j==count($conf["attachment"][$i])-1){
1907
								
1907
 
1908
								#混合資料結尾
1908
								#混合資料結尾
1909
								$attachment=$attachment."--001a11c30ce8aec3550533bfa9ab--\r\n";
1909
								$attachment=$attachment."--001a11c30ce8aec3550533bfa9ab--\r\n";
1910
								
1910
 
1911
								}#if end	
1911
								}#if end
1912
									
1912
 
1913
							#增加到信件內文的結尾
1913
							#增加到信件內文的結尾
1914
							$mailFileContent=$mailFileContent.$attachment;
1914
							$mailFileContent=$mailFileContent.$attachment;
1915
							
1915
 
1916
							}#for end
1916
							}#for end
1917
						
1917
 
1918
						}#if end
1918
						}#if end
1919
					
1919
 
1920
					}#if end
1920
					}#if end
1921
									
1921
 
1922
				}#if end
1922
				}#if end
1923
			
1923
 
1924
			#要寄送的郵件檔案路徑與名稱
1924
			#要寄送的郵件檔案路徑與名稱
1925
			$mailFile=".curlSmtp/mail_at_".$systemTime.".mail";	
1925
			$mailFile=".curlSmtp/mail_at_".$systemTime.".mail";
1926
				
1926
 
1927
			#建立要寄送的郵件檔案
1927
			#建立要寄送的郵件檔案
1928
			#將字串寫入到檔案
1928
			#將字串寫入到檔案
1929
			#回傳結果:
1929
			#回傳結果:
1930
			#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
1930
			#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
1931
			#$result["error"],錯誤訊息陣列.
1931
			#$result["error"],錯誤訊息陣列.
Line 1947... Line 1947...
1947
			#$conf["filenameExtensionStartPoint"]="";
1947
			#$conf["filenameExtensionStartPoint"]="";
1948
			#$conf["repeatNameRule"],字串,遇到相同名稱的檔案要如何加上識別的編號,編號用「\$i」表示,預設為"(\$i)"
1948
			#$conf["repeatNameRule"],字串,遇到相同名稱的檔案要如何加上識別的編號,編號用「\$i」表示,預設為"(\$i)"
1949
			$conf["fileAccess::writeTextIntoFile"]["repeatNameRule"]="_\$i";
1949
			$conf["fileAccess::writeTextIntoFile"]["repeatNameRule"]="_\$i";
1950
			$writeTextIntoFile=fileAccess::writeTextIntoFile($conf["fileAccess::writeTextIntoFile"]);
1950
			$writeTextIntoFile=fileAccess::writeTextIntoFile($conf["fileAccess::writeTextIntoFile"]);
1951
			unset($conf["fileAccess::writeTextIntoFile"]);
1951
			unset($conf["fileAccess::writeTextIntoFile"]);
1952
	
1952
 
1953
			#如果檔案建立失敗
1953
			#如果檔案建立失敗
1954
			if($writeTextIntoFile["status"]=="false"){
1954
			if($writeTextIntoFile["status"]=="false"){
1955
 
1955
 
1956
				#設置錯誤識別
1956
				#設置錯誤識別
1957
				$result["status"]="false";
1957
				$result["status"]="false";
Line 1961... Line 1961...
1961
 
1961
 
1962
				#回傳結果
1962
				#回傳結果
1963
				return $result;
1963
				return $result;
1964
 
1964
 
1965
				}#if end
1965
				}#if end
1966
			
1966
 
1967
			#取得建立好的檔案名稱
1967
			#取得建立好的檔案名稱
1968
			$mailFile=$writeTextIntoFile["fileInfo"]["createdFilePathAndName"];
1968
			$mailFile=$writeTextIntoFile["fileInfo"]["createdFilePathAndName"];
1969
			
1969
 
1970
			#初始化收件人字串
1970
			#初始化收件人字串
1971
			$rcptStr="";
1971
			$rcptStr="";
1972
 
1972
 
1973
			#有幾個收件人就執行幾次
1973
			#有幾個收件人就執行幾次
1974
			foreach($conf["receiverMail"][$i] as $mailTo){
1974
			foreach($conf["receiverMail"][$i] as $mailTo){
1975
				
1975
 
1976
				#串接收件人
1976
				#串接收件人
1977
				$rcptStr=$rcptStr." --mail-rcpt \"".$mailTo."\"";
1977
				$rcptStr=$rcptStr." --mail-rcpt \"".$mailTo."\"";
1978
				
1978
 
1979
				}#for end
1979
				}#for end
1980
 
1980
 
1981
			#初始化允許不安全連線的字串
1981
			#初始化允許不安全連線的字串
1982
			$insecure="";
1982
			$insecure="";
1983
 
1983
 
1984
			#如果允許不安全的連線
1984
			#如果允許不安全的連線
1985
			if($conf["insecure"]==="true"){
1985
			if($conf["insecure"]==="true"){
1986
				
1986
 
1987
				#設置允許不安全連線
1987
				#設置允許不安全連線
1988
				$insecure="--insecure";
1988
				$insecure="--insecure";
1989
				
1989
 
1990
				}#if end
1990
				}#if end
1991
 
1991
 
1992
			#如果登入帳號不用@
1992
			#如果登入帳號不用@
1993
			if($conf["usernameOnly"]==="true"){
1993
			if($conf["usernameOnly"]==="true"){
1994
				
1994
 
1995
				#尋找有無 "@"
1995
				#尋找有無 "@"
1996
				$at=strpos($conf["username"],"@");
1996
				$at=strpos($conf["username"],"@");
1997
				
1997
 
1998
				#如果有找到
1998
				#如果有找到
1999
				if($at!==false){
1999
				if($at!==false){
2000
					
2000
 
2001
					#取得不含 @... 的帳戶名稱
2001
					#取得不含 @... 的帳戶名稱
2002
					$conf["username"]=substr($conf["username"],0,$at);
2002
					$conf["username"]=substr($conf["username"],0,$at);
2003
					
2003
 
2004
					}#if end
2004
					}#if end
2005
				
2005
 
2006
				}#if end
2006
				}#if end
2007
 
2007
 
2008
			#設置要執行的系統命令(寄信)
2008
			#設置要執行的系統命令(寄信)
2009
			$cmdString="curl --ssl --anyauth -1 ".$insecure." --url \"".$conf["mailServer"]."\" -u \"".$conf["username"].":".$conf["password"]."\" --mail-from \"".$conf["mailerMailDisplay"]."\" $rcptStr --upload-file \"".$mailFile."\" -v";
2009
			$cmdString="curl --ssl --anyauth -1 ".$insecure." --url \"".$conf["mailServer"]."\" -u \"".$conf["username"].":".$conf["password"]."\" --mail-from \"".$conf["mailerMailDisplay"]."\" $rcptStr --upload-file \"".$mailFile."\" -v";
2010
			
2010
 
2011
			#取得寄信的指令
2011
			#取得寄信的指令
2012
			$mailCmdArray[]=$cmdString;		
2012
			$mailCmdArray[]=$cmdString;
2013
			
2013
 
2014
			#取得移除信件檔案的指令
2014
			#取得移除信件檔案的指令
2015
			$delMailFileCmd[]="rm \"".$mailFile."\"";
2015
			$delMailFileCmd[]="rm \"".$mailFile."\"";
2016
			
2016
 
2017
			#清空 $mailFileHeader
2017
			#清空 $mailFileHeader
2018
			$mailFileHeader="";
2018
			$mailFileHeader="";
2019
		
2019
 
2020
			}#for end
2020
			}#for end
2021
		
2021
 
2022
		#用curl寄送信件
2022
		#用curl寄送信件
2023
		#函式說明:
2023
		#函式說明:
2024
		#運用nohup與&來達到雖依序執行但不等待前一個指令執行完再執行下一個指令,形成假多工的執行每個指令.
2024
		#運用nohup與&來達到雖依序執行但不等待前一個指令執行完再執行下一個指令,形成假多工的執行每個指令.
2025
		#回傳結果: 
2025
		#回傳結果:
2026
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2026
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2027
		#$result["error"],錯誤訊息陣列.
2027
		#$result["error"],錯誤訊息陣列.
2028
		#$result["function"],當前執行的函數名稱.
2028
		#$result["function"],當前執行的函數名稱.
2029
		#$result["cmd"],執行的指令內容.
2029
		#$result["cmd"],執行的指令內容.
2030
		#$result["output"],爲執行完二元碼後的輸出陣列.
2030
		#$result["output"],爲執行完二元碼後的輸出陣列.
2031
		#必填參數:
2031
		#必填參數:
2032
		#$conf["command"],字串陣列,要執行的指令與.
2032
		#$conf["command"],字串陣列,要執行的指令與.
2033
		$conf["external::multiThreadsShell"]["command"]=$mailCmdArray;
2033
		$conf["external::multiThreadsShell"]["command"]=$mailCmdArray;
2034
		#$conf["fileArgu"],字串,變數__FILE__的內容.
2034
		#$conf["fileArgu"],字串,變數__FILE__的內容.
2035
		$conf["external::multiThreadsShell"]["fileArgu"]=$conf["fileArgu"];		
2035
		$conf["external::multiThreadsShell"]["fileArgu"]=$conf["fileArgu"];
2036
		#可省略參數:
2036
		#可省略參數:
2037
		#$conf["argu"],二維陣列字串,每個指令搭配的參數,預設為空陣列.
2037
		#$conf["argu"],二維陣列字串,每個指令搭配的參數,預設為空陣列.
2038
		#$conf["argu"]=array(array());
2038
		#$conf["argu"]=array(array());
2039
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
2039
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
2040
		#$conf["enablePrintDescription"]="true";
2040
		#$conf["enablePrintDescription"]="true";
Line 2046... Line 2046...
2046
		#$conf["username"]=array("");
2046
		#$conf["username"]=array("");
2047
		#$conf["password"],字串陣列,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
2047
		#$conf["password"],字串陣列,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
2048
		#$conf["password"]=array("");
2048
		#$conf["password"]=array("");
2049
		$multiThreadsShell=external::multiThreadsShell($conf["external::multiThreadsShell"]);
2049
		$multiThreadsShell=external::multiThreadsShell($conf["external::multiThreadsShell"]);
2050
		unset($conf["external::multiThreadsShell"]);
2050
		unset($conf["external::multiThreadsShell"]);
2051
		
2051
 
2052
		#如果寄信失敗
2052
		#如果寄信失敗
2053
		if($multiThreadsShell["status"]=="false"){
2053
		if($multiThreadsShell["status"]=="false"){
2054
		
2054
 
2055
			#設置錯誤識別
2055
			#設置錯誤識別
2056
			$result["status"]="false";
2056
			$result["status"]="false";
2057
 
2057
 
2058
			#設置錯誤資訊
2058
			#設置錯誤資訊
2059
			$result["error"]=$multiThreadsShell;
2059
			$result["error"]=$multiThreadsShell;
2060
 
2060
 
2061
			#回傳結果
2061
			#回傳結果
2062
			return $result;
2062
			return $result;
2063
		
2063
 
2064
			}#if end
2064
			}#if end
2065
		
2065
 
2066
		#取得執行的指令
2066
		#取得執行的指令
2067
		$result["cmd"]=$multiThreadsShell["cmd"];
2067
		$result["cmd"]=$multiThreadsShell["cmd"];
2068
		
2068
 
2069
		/*
2069
		/*
2070
		#移除信件檔案
2070
		#移除信件檔案
2071
		#函式說明:
2071
		#函式說明:
2072
		#運用nohup與&來達到雖依序執行但不等待前一個指令執行完再執行下一個指令,形成假多工的執行每個指令.
2072
		#運用nohup與&來達到雖依序執行但不等待前一個指令執行完再執行下一個指令,形成假多工的執行每個指令.
2073
		#回傳結果: 
2073
		#回傳結果:
2074
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2074
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2075
		#$result["error"],錯誤訊息陣列.
2075
		#$result["error"],錯誤訊息陣列.
2076
		#$result["function"],當前執行的函數名稱.
2076
		#$result["function"],當前執行的函數名稱.
2077
		#$result["cmd"],執行的指令內容.
2077
		#$result["cmd"],執行的指令內容.
2078
		#$result["output"],爲執行完二元碼後的輸出陣列.
2078
		#$result["output"],爲執行完二元碼後的輸出陣列.
2079
		#必填參數:
2079
		#必填參數:
2080
		#$conf["command"],字串陣列,要執行的指令與.
2080
		#$conf["command"],字串陣列,要執行的指令與.
2081
		$conf["external::multiThreadsShell"]["command"]=$delMailFileCmd;
2081
		$conf["external::multiThreadsShell"]["command"]=$delMailFileCmd;
2082
		#$conf["fileArgu"],字串,變數__FILE__的內容.
2082
		#$conf["fileArgu"],字串,變數__FILE__的內容.
2083
		$conf["external::multiThreadsShell"]["fileArgu"]=$conf["fileArgu"];		
2083
		$conf["external::multiThreadsShell"]["fileArgu"]=$conf["fileArgu"];
2084
		#可省略參數:
2084
		#可省略參數:
2085
		#$conf["argu"],二維陣列字串,每個指令搭配的參數,預設為空陣列.
2085
		#$conf["argu"],二維陣列字串,每個指令搭配的參數,預設為空陣列.
2086
		#$conf["argu"]=array(array());
2086
		#$conf["argu"]=array(array());
2087
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
2087
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
2088
		#$conf["enablePrintDescription"]="true";
2088
		#$conf["enablePrintDescription"]="true";
Line 2094... Line 2094...
2094
		#$conf["username"]=array("");
2094
		#$conf["username"]=array("");
2095
		#$conf["password"],字串陣列,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
2095
		#$conf["password"],字串陣列,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
2096
		#$conf["password"]=array("");
2096
		#$conf["password"]=array("");
2097
		$multiThreadsShell=external::multiThreadsShell($conf["external::multiThreadsShell"]);
2097
		$multiThreadsShell=external::multiThreadsShell($conf["external::multiThreadsShell"]);
2098
		unset($conf["external::multiThreadsShell"]);
2098
		unset($conf["external::multiThreadsShell"]);
2099
		
2099
 
2100
		#如果移除信件檔案失敗
2100
		#如果移除信件檔案失敗
2101
		if($multiThreadsShell["status"]=="false"){
2101
		if($multiThreadsShell["status"]=="false"){
2102
			
2102
 
2103
			#設置錯誤識別
2103
			#設置錯誤識別
2104
			$result["status"]="false";
2104
			$result["status"]="false";
2105
 
2105
 
2106
			#設置錯誤資訊
2106
			#設置錯誤資訊
2107
			$result["error"]=$multiThreadsShell;
2107
			$result["error"]=$multiThreadsShell;
2108
 
2108
 
2109
			#回傳結果
2109
			#回傳結果
2110
			return $result;
2110
			return $result;
2111
		
2111
 
2112
			}
2112
			}
2113
		
2113
 
2114
		*/
2114
		*/
2115
			
2115
 
2116
		#設置執行正常
2116
		#設置執行正常
2117
		$result["status"]="true";
2117
		$result["status"]="true";
2118
					
2118
 
2119
		#回傳結果
2119
		#回傳結果
2120
		return $result;
2120
		return $result;
2121
					
2121
 
2122
		}#function multiCurlSmtp end
2122
		}#function multiCurlSmtp end
2123
	
2123
 
2124
	/*
2124
	/*
2125
	#函式說明:
2125
	#函式說明:
2126
	#透過php的mail函數寄信
2126
	#透過php的mail函數寄信
2127
	#回傳結果:
2127
	#回傳結果:
2128
	#$result["status"],寄信的情況,若爲"true",則十之八九沒有問題.
2128
	#$result["status"],寄信的情況,若爲"true",則十之八九沒有問題.
Line 2133... Line 2133...
2133
	$conf["to"]=array();
2133
	$conf["to"]=array();
2134
	#$conf["subject"],字串,郵件標題.
2134
	#$conf["subject"],字串,郵件標題.
2135
	$conf["subject"]="";
2135
	$conf["subject"]="";
2136
	#$conf["content"],字串,要寄送的訊息內容.
2136
	#$conf["content"],字串,要寄送的訊息內容.
2137
	$conf["content"]="";
2137
	$conf["content"]="";
2138
	#可省略參數: 
2138
	#可省略參數:
2139
	#$conf["mailerEmail"],字串,顯示的寄件人.
2139
	#$conf["mailerEmail"],字串,顯示的寄件人.
2140
	#$conf["mailerEmail"]="";
2140
	#$conf["mailerEmail"]="";
2141
	#參考資料:
2141
	#參考資料:
2142
	#mail=>https://www.php.net/manual/en/function.mail.php
2142
	#mail=>https://www.php.net/manual/en/function.mail.php
2143
	#Internet Message Format=>http://www.faqs.org/rfcs/rfc2822
2143
	#Internet Message Format=>http://www.faqs.org/rfcs/rfc2822
2144
	#備註:
2144
	#備註:
2145
	#無.
2145
	#無.
2146
	*/
2146
	*/
2147
	public static function sendMail(&$conf){
2147
	public static function sendMail(&$conf){
2148
		
2148
 
2149
		#初始化要回傳的結果
2149
		#初始化要回傳的結果
2150
		$result=array();
2150
		$result=array();
2151
 
2151
 
2152
		#儲存當前執行的函數
2152
		#儲存當前執行的函數
2153
		$result["function"]=__FUNCTION__;
2153
		$result["function"]=__FUNCTION__;
2154
 
2154
 
2155
		#如果 $conf 不為陣列
2155
		#如果 $conf 不為陣列
2156
		if(gettype($conf)!="array"){
2156
		if(gettype($conf)!="array"){
2157
			
2157
 
2158
			#設置執行失敗
2158
			#設置執行失敗
2159
			$result["status"]="false";
2159
			$result["status"]="false";
2160
			
2160
 
2161
			#設置執行錯誤訊息
2161
			#設置執行錯誤訊息
2162
			$result["error"][]="\$conf變數須為陣列形態";
2162
			$result["error"][]="\$conf變數須為陣列形態";
2163
 
2163
 
2164
			#如果傳入的參數為 null
2164
			#如果傳入的參數為 null
2165
			if($conf==null){
2165
			if($conf==null){
2166
				
2166
 
2167
				#設置執行錯誤訊息
2167
				#設置執行錯誤訊息
2168
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
2168
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
2169
				
2169
 
2170
				}#if end
2170
				}#if end
2171
 
2171
 
2172
			#回傳結果
2172
			#回傳結果
2173
			return $result;
2173
			return $result;
2174
	
2174
 
2175
			}#if end
2175
			}#if end
2176
	
2176
 
2177
		#檢查參數
2177
		#檢查參數
2178
		#函式說明:
2178
		#函式說明:
2179
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
2179
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
2180
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2180
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2181
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
2181
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
Line 2190... Line 2190...
2190
		#必填寫的參數:
2190
		#必填寫的參數:
2191
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
2191
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
2192
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
2192
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
2193
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
2193
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
2194
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("to","subject","content");
2194
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("to","subject","content");
2195
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); 
2195
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
2196
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array","string","string");
2196
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array","string","string");
2197
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
2197
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
2198
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
2198
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
2199
		#可以省略的參數:
2199
		#可以省略的參數:
2200
		#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
2200
		#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
2201
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
2201
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
2202
		#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
2202
		#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
2203
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("mailerEmail");
2203
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("mailerEmail");
2204
		#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double"); 
2204
		#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
2205
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
2205
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
2206
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
2206
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
2207
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null);
2207
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null);
2208
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
2208
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
2209
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("subject","plainBody","htmlBody","receiverMail","receiverMailDisplay","receiverNameDisplay");
2209
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("subject","plainBody","htmlBody","receiverMail","receiverMailDisplay","receiverNameDisplay");
2210
		#參考資料來源:
2210
		#參考資料來源:
2211
		#array_keys=>http://php.net/manual/en/function.array-keys.php
2211
		#array_keys=>http://php.net/manual/en/function.array-keys.php
2212
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
2212
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
2213
		unset($conf["variableCheck::checkArguments"]);
2213
		unset($conf["variableCheck::checkArguments"]);
2214
	
2214
 
2215
		#如果檢查失敗
2215
		#如果檢查失敗
2216
		if($checkArguments["status"]=="false"){
2216
		if($checkArguments["status"]=="false"){
2217
			
2217
 
2218
			#設置錯誤識別
2218
			#設置錯誤識別
2219
			$result["status"]="false";
2219
			$result["status"]="false";
2220
			
2220
 
2221
			#設置錯誤訊息
2221
			#設置錯誤訊息
2222
			$result["error"]=$checkArguments;
2222
			$result["error"]=$checkArguments;
2223
			
2223
 
2224
			#回傳結果
2224
			#回傳結果
2225
			return $result;
2225
			return $result;
2226
			
2226
 
2227
			}#if end
2227
			}#if end
2228
	
2228
 
2229
		#如果檢查不通過
2229
		#如果檢查不通過
2230
		if($checkArguments["passed"]=="false"){
2230
		if($checkArguments["passed"]=="false"){
2231
			
2231
 
2232
			#設置錯誤識別
2232
			#設置錯誤識別
2233
			$result["status"]="false";
2233
			$result["status"]="false";
2234
			
2234
 
2235
			#設置錯誤訊息
2235
			#設置錯誤訊息
2236
			$result["error"]=$checkArguments;
2236
			$result["error"]=$checkArguments;
2237
			
2237
 
2238
			#回傳結果
2238
			#回傳結果
2239
			return $result;
2239
			return $result;
2240
			
2240
 
2241
			}#if end
2241
			}#if end
2242
		
2242
 
2243
		#函式說明:
2243
		#函式說明:
2244
		#將一維陣列轉換為用特定符號間隔的字串,ex:array("1","2","3") to "a;b;c;".
2244
		#將一維陣列轉換為用特定符號間隔的字串,ex:array("1","2","3") to "a;b;c;".
2245
		#回傳的結果:
2245
		#回傳的結果:
2246
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2246
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2247
		#$result["function"],當前執行的function名稱
2247
		#$result["function"],當前執行的function名稱
Line 2260... Line 2260...
2260
		#無.
2260
		#無.
2261
		#備註:
2261
		#備註:
2262
		#無.
2262
		#無.
2263
		$arrayToString=arrays::arrayToString($conf["arrays::arrayToString"]);
2263
		$arrayToString=arrays::arrayToString($conf["arrays::arrayToString"]);
2264
		unset($conf["arrays::arrayToString"]);
2264
		unset($conf["arrays::arrayToString"]);
2265
		
2265
 
2266
		#如果檢查失敗
2266
		#如果檢查失敗
2267
		if($arrayToString["status"]=="false"){
2267
		if($arrayToString["status"]=="false"){
2268
			
2268
 
2269
			#設置錯誤識別
2269
			#設置錯誤識別
2270
			$result["status"]="false";
2270
			$result["status"]="false";
2271
			
2271
 
2272
			#設置錯誤訊息
2272
			#設置錯誤訊息
2273
			$result["error"]=$arrayToString;
2273
			$result["error"]=$arrayToString;
2274
			
2274
 
2275
			#回傳結果
2275
			#回傳結果
2276
			return $result;
2276
			return $result;
2277
			
2277
 
2278
			}#if end
2278
			}#if end
2279
		
2279
 
2280
		$to = $arrayToString["content"];
2280
		$to = $arrayToString["content"];
2281
		$subject = $conf["subject"];
2281
		$subject = $conf["subject"];
2282
		$message = $conf["content"];
2282
		$message = $conf["content"];
2283
		
2283
 
2284
		# In case any of our lines are larger than 70 characters, we should use wordwrap()
2284
		# In case any of our lines are larger than 70 characters, we should use wordwrap()
2285
		$message = wordwrap($message, 70, "\r\n");
2285
		$message = wordwrap($message, 70, "\r\n");
2286
		
2286
 
2287
		#初始化mail header為空
2287
		#初始化mail header為空
2288
		$headers = "";
2288
		$headers = "";
2289
		
2289
 
2290
		#如果有設置寄件人資訊
2290
		#如果有設置寄件人資訊
2291
		if(isset($conf["mailerEmail"])){
2291
		if(isset($conf["mailerEmail"])){
2292
		
2292
 
2293
			#設置寄件人資訊
2293
			#設置寄件人資訊
2294
			$headers = "From: ".$conf["mailerEmail"];
2294
			$headers = "From: ".$conf["mailerEmail"];
2295
		
2295
 
2296
			}#if end
2296
			}#if end
2297
		
2297
 
2298
		#寄信
2298
		#寄信
2299
		$mailResult=mail($to, $subject, $message, $headers);
2299
		$mailResult=mail($to, $subject, $message, $headers);
2300
			
2300
 
2301
		#初始化執行正常
2301
		#初始化執行正常
2302
		$result["status"]="true";	
2302
		$result["status"]="true";
2303
			
2303
 
2304
		#如果寄信失敗
2304
		#如果寄信失敗
2305
		if(!$mailResult){
2305
		if(!$mailResult){
2306
			
2306
 
2307
			#設置執行不正常
2307
			#設置執行不正常
2308
			$result["status"]="false";
2308
			$result["status"]="false";
2309
		
2309
 
2310
			#回傳結果
2310
			#回傳結果
2311
			return $result;
2311
			return $result;
2312
		
2312
 
2313
			}#if end
2313
			}#if end
2314
			
2314
 
2315
		#回傳結果
2315
		#回傳結果
2316
		return $result;	
2316
		return $result;
2317
			
2317
 
2318
		}#function sendMail end
2318
		}#function sendMail end
2319
	
2319
 
2320
	/*
2320
	/*
2321
	#函式說明:
2321
	#函式說明:
2322
	#使用 php-pear-smtp 來透過SMTP伺服器寄信.
2322
	#使用 php-pear-smtp 來透過SMTP伺服器寄信.
2323
	#回傳結果:
2323
	#回傳結果:
2324
	#$result["status"],執行正常與否,"true"代表正常;反之為"false".
2324
	#$result["status"],執行正常與否,"true"代表正常;反之為"false".
Line 2370... Line 2370...
2370
	#mail body boundary=>https://www.w3.org/Protocols/rfc1341/7_2_Multipart.html
2370
	#mail body boundary=>https://www.w3.org/Protocols/rfc1341/7_2_Multipart.html
2371
	#備註:
2371
	#備註:
2372
	#需要php-pear-Net-SMTP
2372
	#需要php-pear-Net-SMTP
2373
	*/
2373
	*/
2374
	public static function pear_smtp_send(&$conf){
2374
	public static function pear_smtp_send(&$conf){
2375
	
2375
 
2376
		#初始化要回傳的結果
2376
		#初始化要回傳的結果
2377
		$result=array();
2377
		$result=array();
2378
 
2378
 
2379
		#取得當前執行的函數名稱
2379
		#取得當前執行的函數名稱
2380
		$result["function"]=__FUNCTION__;
2380
		$result["function"]=__FUNCTION__;
Line 2415... Line 2415...
2415
 
2415
 
2416
			#回傳結果
2416
			#回傳結果
2417
			return $result;
2417
			return $result;
2418
 
2418
 
2419
			}#if end
2419
			}#if end
2420
		
2420
 
2421
		#檢查參數
2421
		#檢查參數
2422
		#函式說明:
2422
		#函式說明:
2423
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
2423
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
2424
		#回傳結果:
2424
		#回傳結果:
2425
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2425
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
Line 2471... Line 2471...
2471
		#array_keys=>http://php.net/manual/en/function.array-keys.php
2471
		#array_keys=>http://php.net/manual/en/function.array-keys.php
2472
		#備註:
2472
		#備註:
2473
		#無.
2473
		#無.
2474
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
2474
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
2475
		unset($conf["variableCheck::checkArguments"]);
2475
		unset($conf["variableCheck::checkArguments"]);
2476
	
2476
 
2477
		#如果檢查失敗
2477
		#如果檢查失敗
2478
		if($checkArguments["status"]==="false"){
2478
		if($checkArguments["status"]==="false"){
2479
			
2479
 
2480
			#設置錯誤識別
2480
			#設置錯誤識別
2481
			$result["status"]="false";
2481
			$result["status"]="false";
2482
			
2482
 
2483
			#設置錯誤訊息
2483
			#設置錯誤訊息
2484
			$result["error"]=$checkArguments;
2484
			$result["error"]=$checkArguments;
2485
			
2485
 
2486
			#回傳結果
2486
			#回傳結果
2487
			return $result;
2487
			return $result;
2488
			
2488
 
2489
			}#if end
2489
			}#if end
2490
	
2490
 
2491
		#如果檢查不通過
2491
		#如果檢查不通過
2492
		if($checkArguments["passed"]==="false"){
2492
		if($checkArguments["passed"]==="false"){
2493
			
2493
 
2494
			#設置錯誤識別
2494
			#設置錯誤識別
2495
			$result["status"]="false";
2495
			$result["status"]="false";
2496
			
2496
 
2497
			#設置錯誤訊息
2497
			#設置錯誤訊息
2498
			$result["error"]=$checkArguments;
2498
			$result["error"]=$checkArguments;
2499
			
2499
 
2500
			#回傳結果
2500
			#回傳結果
2501
			return $result;
2501
			return $result;
2502
			
2502
 
2503
			}#if end
2503
			}#if end
2504
		
2504
 
2505
		#設置pear套件Net SMTP的位置
2505
		#設置pear套件Net SMTP的位置
2506
		$locationOfPearNetSmtp="/usr/share/pear/Net/SMTP.php";
2506
		$locationOfPearNetSmtp="/usr/share/pear/Net/SMTP.php";
2507
		
2507
 
2508
		#檢查需要的pear套件是否存在
2508
		#檢查需要的pear套件是否存在
2509
		#函式說明:
2509
		#函式說明:
2510
		#檢查多個檔案與資料夾是否存在.
2510
		#檢查多個檔案與資料夾是否存在.
2511
		#回傳的結果:
2511
		#回傳的結果:
2512
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
2512
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
Line 2536... Line 2536...
2536
		#備註:
2536
		#備註:
2537
		#函數file_exists檢查的路徑為檔案系統的路徑
2537
		#函數file_exists檢查的路徑為檔案系統的路徑
2538
		#$result["varName"][$i]結果未實作
2538
		#$result["varName"][$i]結果未實作
2539
		$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["filAccess::checkMultiFileExist"]);
2539
		$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["filAccess::checkMultiFileExist"]);
2540
		unset($conf["filAccess::checkMultiFileExist"]);
2540
		unset($conf["filAccess::checkMultiFileExist"]);
2541
		
2541
 
2542
		#如果檢查失敗
2542
		#如果檢查失敗
2543
		if($checkMultiFileExist["status"]==="false"){
2543
		if($checkMultiFileExist["status"]==="false"){
2544
			
2544
 
2545
			#設置錯誤識別
2545
			#設置錯誤識別
2546
			$result["status"]="false";
2546
			$result["status"]="false";
2547
			
2547
 
2548
			#設置錯誤訊息
2548
			#設置錯誤訊息
2549
			$result["error"]=$checkMultiFileExist;
2549
			$result["error"]=$checkMultiFileExist;
2550
			
2550
 
2551
			#回傳結果
2551
			#回傳結果
2552
			return $result;
2552
			return $result;
2553
			
2553
 
2554
			}#if end
2554
			}#if end
2555
			
2555
 
2556
		#如果不存在
2556
		#如果不存在
2557
		if($checkMultiFileExist["allExist"]==="false"){
2557
		if($checkMultiFileExist["allExist"]==="false"){
2558
			
2558
 
2559
			#設置錯誤識別
2559
			#設置錯誤識別
2560
			$result["status"]="false";
2560
			$result["status"]="false";
2561
			
2561
 
2562
			#設置錯誤訊息
2562
			#設置錯誤訊息
2563
			$result["error"][]=$checkMultiFileExist;
2563
			$result["error"][]=$checkMultiFileExist;
2564
			
2564
 
2565
			#設置錯誤訊息
2565
			#設置錯誤訊息
2566
			$result["error"][]="請確認 ".$locationOfPearNetSmtp." 可被存取";
2566
			$result["error"][]="請確認 ".$locationOfPearNetSmtp." 可被存取";
2567
			
2567
 
2568
			#回傳結果
2568
			#回傳結果
2569
			return $result;
2569
			return $result;
2570
			
2570
 
2571
			}#if end
2571
			}#if end
2572
		
2572
 
2573
		#匯入需要的pear套件
2573
		#匯入需要的pear套件
2574
		require_once($locationOfPearNetSmtp); 
2574
		require_once($locationOfPearNetSmtp);
2575
		
2575
 
2576
		#create smtp object
2576
		#create smtp object
2577
		$smtp = new \Net_SMTP($conf["mailServer"], $conf["mailServerPort"]);
2577
		$smtp = new \Net_SMTP($conf["mailServer"], $conf["mailServerPort"]);
2578
		
2578
 
2579
		#如果有錯誤
2579
		#如果有錯誤
2580
		if(\PEAR::isError($error = $smtp->connect())){
2580
		if(\PEAR::isError($error = $smtp->connect())){
2581
			
2581
 
2582
			#設置錯誤識別
2582
			#設置錯誤識別
2583
			$result["status"]="false";
2583
			$result["status"]="false";
2584
			
2584
 
2585
			#設置錯誤訊息
2585
			#設置錯誤訊息
2586
			$result["error"]=$error->getMessage();
2586
			$result["error"]=$error->getMessage();
2587
			
2587
 
2588
			#回傳結果
2588
			#回傳結果
2589
			return $result;
2589
			return $result;
2590
			
2590
 
2591
			}#if end
2591
			}#if end
2592
		
2592
 
2593
		#嘗試進行登入認證,方式目前都用"PLAIN"
2593
		#嘗試進行登入認證,方式目前都用"PLAIN"
2594
		$smtp->auth($conf["username"],$conf["password"],"PLAIN");
2594
		$smtp->auth($conf["username"],$conf["password"],"PLAIN");
2595
		
2595
 
2596
		# smtp command "MAIL FROM:"
2596
		# smtp command "MAIL FROM:"
2597
		$smtp->mailFrom($conf["mailerNameDisplay"]." <".$conf["mailerMailDisplay"].">");
2597
		$smtp->mailFrom($conf["mailerNameDisplay"]." <".$conf["mailerMailDisplay"].">");
2598
		
2598
 
2599
		#初始化儲存 email head 的變數
2599
		#初始化儲存 email head 的變數
2600
		$head="";
2600
		$head="";
2601
		
2601
 
2602
		#初始化儲存 email data 的變數
2602
		#初始化儲存 email data 的變數
2603
		$data="";
2603
		$data="";
2604
		
2604
 
2605
		#設置收件人
2605
		#設置收件人
2606
		foreach($conf["receiverMail"] as $index => $receiverMail){
2606
		foreach($conf["receiverMail"] as $index => $receiverMail){
2607
		
2607
 
2608
			#若無顯示名稱參數
2608
			#若無顯示名稱參數
2609
			if(!isset($conf["receiverNameDisplay"][$index])){
2609
			if(!isset($conf["receiverNameDisplay"][$index])){
2610
			
2610
 
2611
				#若無顯示名稱參數,則預設採email來顯示.
2611
				#若無顯示名稱參數,則預設採email來顯示.
2612
				$conf["receiverNameDisplay"][$index]=$receiverMail;
2612
				$conf["receiverNameDisplay"][$index]=$receiverMail;
2613
			
2613
 
2614
				}#if end
2614
				}#if end
2615
		
2615
 
2616
			#設置收件人的email與顯示名稱
2616
			#設置收件人的email與顯示名稱
2617
			$receiverMail=$conf["receiverNameDisplay"][$index]." <".$receiverMail.">";
2617
			$receiverMail=$conf["receiverNameDisplay"][$index]." <".$receiverMail.">";
2618
		
2618
 
2619
			#設置To:資訊
2619
			#設置To:資訊
2620
			$head=$head."To: ".$receiverMail."\r\n";
2620
			$head=$head."To: ".$receiverMail."\r\n";
2621
			
2621
 
2622
			#如果新增收件人失敗
2622
			#如果新增收件人失敗
2623
			if(\PEAR::isError($res=$smtp->rcptTo($receiverMail))){
2623
			if(\PEAR::isError($res=$smtp->rcptTo($receiverMail))){
2624
			
2624
 
2625
				#設置錯誤識別
2625
				#設置錯誤識別
2626
				$result["status"]="false";
2626
				$result["status"]="false";
2627
			
2627
 
2628
				#設置錯誤訊息
2628
				#設置錯誤訊息
2629
				$result["error"]="Unable to add recipient <".$receiverMail.">: ".$res->getMessage();
2629
				$result["error"]="Unable to add recipient <".$receiverMail.">: ".$res->getMessage();
2630
			
2630
 
2631
				#回傳結果
2631
				#回傳結果
2632
				return $result;
2632
				return $result;
2633
			
2633
 
2634
				}#if end
2634
				}#if end
2635
				
2635
 
2636
			}#foreach end
2636
			}#foreach end
2637
		
2637
 
2638
		#設置sender資訊
2638
		#設置sender資訊
2639
		$head=$head."From: ".$conf["mailerNameDisplay"]." <".$conf["mailerMailDisplay"].">"."\r\n";
2639
		$head=$head."From: ".$conf["mailerNameDisplay"]." <".$conf["mailerMailDisplay"].">"."\r\n";
2640
		
2640
 
2641
		#設置Replay-to資訊
2641
		#設置Replay-to資訊
2642
		$head=$head."Reply-To: ".$conf["mailerNameDisplay"]." <".$conf["mailerMailDisplay"].">"."\r\n";
2642
		$head=$head."Reply-To: ".$conf["mailerNameDisplay"]." <".$conf["mailerMailDisplay"].">"."\r\n";
2643
		
2643
 
2644
		#如果有設置回報已讀通知
2644
		#如果有設置回報已讀通知
2645
		if($conf["notifyReceived"]==="true"){
2645
		if($conf["notifyReceived"]==="true"){
2646
		
2646
 
2647
			#Disposition-Notification-To: liveuser@qbpwcf.org
2647
			#Disposition-Notification-To: liveuser@qbpwcf.org
2648
			$head=$head."Disposition-Notification-To: ".$conf["mailerMailDisplay"]."\r\n";
2648
			$head=$head."Disposition-Notification-To: ".$conf["mailerMailDisplay"]."\r\n";
2649
		
2649
 
2650
			}#if end
2650
			}#if end
2651
		
2651
 
2652
		#建立body中的Subject
2652
		#建立body中的Subject
2653
		$head=$head."Subject: ".$conf["subject"]."\r\n";
2653
		$head=$head."Subject: ".$conf["subject"]."\r\n";
2654
		
2654
 
2655
		#函式說明:
2655
		#函式說明:
2656
		#使用 linux 的 uuid 指令來產生 uuid 字串
2656
		#使用 linux 的 uuid 指令來產生 uuid 字串
2657
		#回傳結果:
2657
		#回傳結果:
2658
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2658
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2659
		#$result["error"],錯誤訊息.
2659
		#$result["error"],錯誤訊息.
Line 2666... Line 2666...
2666
		#參考資料:
2666
		#參考資料:
2667
		#無.
2667
		#無.
2668
		#備註:
2668
		#備註:
2669
		#無.
2669
		#無.
2670
		$uuid=cmd::uuid();
2670
		$uuid=cmd::uuid();
2671
		
2671
 
2672
		#如果取得uuid失敗
2672
		#如果取得uuid失敗
2673
		if($uuid["status"]==="false"){
2673
		if($uuid["status"]==="false"){
2674
		
2674
 
2675
			#設置錯誤識別
2675
			#設置錯誤識別
2676
			$result["status"]="false";
2676
			$result["status"]="false";
2677
		
2677
 
2678
			#設置錯誤訊息
2678
			#設置錯誤訊息
2679
			$result["error"][]="Unable to create Message-ID";
2679
			$result["error"][]="Unable to create Message-ID";
2680
		
2680
 
2681
			#設置錯誤訊息
2681
			#設置錯誤訊息
2682
			$result["error"][]=$uuid;
2682
			$result["error"][]=$uuid;
2683
		
2683
 
2684
			#回傳結果
2684
			#回傳結果
2685
			return $result;
2685
			return $result;
2686
		
2686
 
2687
			}#if end
2687
			}#if end
2688
		
2688
 
2689
		#函式說明:
2689
		#函式說明:
2690
		#將字串特定關鍵字與其前面的內容剔除
2690
		#將字串特定關鍵字與其前面的內容剔除
2691
		#回傳結果:
2691
		#回傳結果:
2692
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2692
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2693
		#$result["error"],錯誤訊息陣列.
2693
		#$result["error"],錯誤訊息陣列.
Line 2712... Line 2712...
2712
		#無.
2712
		#無.
2713
		#備註:
2713
		#備註:
2714
		#無.
2714
		#無.
2715
		$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf["stringProcess::delStrBeforeKeyWord"]);
2715
		$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf["stringProcess::delStrBeforeKeyWord"]);
2716
		unset($conf["stringProcess::delStrBeforeKeyWord"]);
2716
		unset($conf["stringProcess::delStrBeforeKeyWord"]);
2717
		
2717
 
2718
		#如果取得Message-ID的domain失敗
2718
		#如果取得Message-ID的domain失敗
2719
		if($delStrBeforeKeyWord["status"]==="false"){
2719
		if($delStrBeforeKeyWord["status"]==="false"){
2720
		
2720
 
2721
			#設置錯誤識別
2721
			#設置錯誤識別
2722
			$result["status"]="false";
2722
			$result["status"]="false";
2723
		
2723
 
2724
			#設置錯誤訊息
2724
			#設置錯誤訊息
2725
			$result["error"][]="Unable to create domain of Message-ID";
2725
			$result["error"][]="Unable to create domain of Message-ID";
2726
		
2726
 
2727
			#設置錯誤訊息
2727
			#設置錯誤訊息
2728
			$result["error"][]=$delStrBeforeKeyWord;
2728
			$result["error"][]=$delStrBeforeKeyWord;
2729
		
2729
 
2730
			#回傳結果
2730
			#回傳結果
2731
			return $result;
2731
			return $result;
2732
		
2732
 
2733
			}#if end
2733
			}#if end
2734
		
2734
 
2735
		#取得Message-ID對應的domain
2735
		#取得Message-ID對應的domain
2736
		$MessageIdDomain=$delStrBeforeKeyWord["content"];
2736
		$MessageIdDomain=$delStrBeforeKeyWord["content"];
2737
		
2737
 
2738
		#建立Message-ID
2738
		#建立Message-ID
2739
		$head=$head."Message-ID: <".$uuid["content"]."@".$MessageIdDomain.">"."\r\n";;
2739
		$head=$head."Message-ID: <".$uuid["content"]."@".$MessageIdDomain.">"."\r\n";;
2740
		
2740
 
2741
		#設置User-Agent
2741
		#設置User-Agent
2742
		$head=$head."User-Agent: ".$conf["userAgent"]."\r\n";
2742
		$head=$head."User-Agent: ".$conf["userAgent"]."\r\n";
2743
		
2743
 
2744
		#設置Date: 
2744
		#設置Date:
2745
		$head=$head."Date: ".gmdate("Y-m-d H:i:s")."\r\n";
2745
		$head=$head."Date: ".gmdate("Y-m-d H:i:s")."\r\n";
2746
		
2746
 
2747
		#如果有設置 org
2747
		#如果有設置 org
2748
		if(isset($conf["org"])){
2748
		if(isset($conf["org"])){
2749
		
2749
 
2750
			#設置 Organization
2750
			#設置 Organization
2751
			$head=$head."Organization: ".$conf["org"]."\r\n";
2751
			$head=$head."Organization: ".$conf["org"]."\r\n";
2752
		
2752
 
2753
			}#if end
2753
			}#if end
2754
		
2754
 
2755
		#函式說明:
2755
		#函式說明:
2756
		#建立以圖片(PNG格式)呈現的驗證碼.
2756
		#建立以圖片(PNG格式)呈現的驗證碼.
2757
		#回傳的解果:
2757
		#回傳的解果:
2758
		#$result["status"],執行是否正常,"true"代表執行成功,"false"代表執行失敗.
2758
		#$result["status"],執行是否正常,"true"代表執行成功,"false"代表執行失敗.
2759
		#$result["error"],錯誤訊息.
2759
		#$result["error"],錯誤訊息.
Line 2781... Line 2781...
2781
		#無.
2781
		#無.
2782
		#備註:
2782
		#備註:
2783
		#無.
2783
		#無.
2784
		$validationCode=authenticate::validationCode($conf["authenticate::validationCode"]);
2784
		$validationCode=authenticate::validationCode($conf["authenticate::validationCode"]);
2785
		unset($conf["authenticate::validationCode"]);
2785
		unset($conf["authenticate::validationCode"]);
2786
		
2786
 
2787
		#如果檢查失敗
2787
		#如果檢查失敗
2788
		if($validationCode["status"]==="false"){
2788
		if($validationCode["status"]==="false"){
2789
			
2789
 
2790
			#設置錯誤識別
2790
			#設置錯誤識別
2791
			$result["status"]="false";
2791
			$result["status"]="false";
2792
			
2792
 
2793
			#設置錯誤訊息
2793
			#設置錯誤訊息
2794
			$result["error"]=$validationCode;
2794
			$result["error"]=$validationCode;
2795
			
2795
 
2796
			#回傳結果
2796
			#回傳結果
2797
			return $result;
2797
			return $result;
2798
			
2798
 
2799
			}#if end
2799
			}#if end
2800
		
2800
 
2801
		#初始化 boundary
2801
		#初始化 boundary
2802
		$boundary=$validationCode["randNumberWord"];
2802
		$boundary=$validationCode["randNumberWord"];
2803
				
2803
 
2804
		#初始化 boundary start
2804
		#初始化 boundary start
2805
		$boundaryS="--".$boundary;
2805
		$boundaryS="--".$boundary;
2806
		
2806
 
2807
		#初始化 boundary end
2807
		#初始化 boundary end
2808
		$boundaryE=$boundaryS."--";
2808
		$boundaryE=$boundaryS."--";
2809
		
2809
 
2810
		#取得放置於head的Contet-Type描述
2810
		#取得放置於head的Contet-Type描述
2811
		$contentDescInHead="Content-Type: multipart/alternative; boundary=\"".$boundary."\"\r\n";
2811
		$contentDescInHead="Content-Type: multipart/alternative; boundary=\"".$boundary."\"\r\n";
2812
		
2812
 
2813
		#設置信件本文(純文字與html兩種)
2813
		#設置信件本文(純文字與html兩種)
2814
		$data=$data.$boundaryS."\r\n";
2814
		$data=$data.$boundaryS."\r\n";
2815
		$data=$data."Content-Type: text/plain; charset=UTF-8\r\n";
2815
		$data=$data."Content-Type: text/plain; charset=UTF-8\r\n";
2816
		$data=$data."\r\n";
2816
		$data=$data."\r\n";
2817
		$data=$data.$conf["plainBody"]."\r\n";
2817
		$data=$data.$conf["plainBody"]."\r\n";
Line 2819... Line 2819...
2819
		$data=$data.$boundaryS."\r\n";
2819
		$data=$data.$boundaryS."\r\n";
2820
		$data=$data."Content-Type: text/html; charset=UTF-8\r\n";
2820
		$data=$data."Content-Type: text/html; charset=UTF-8\r\n";
2821
		$data=$data."\r\n";
2821
		$data=$data."\r\n";
2822
		$data=$data.$conf["htmlBody"]."\r\n";
2822
		$data=$data.$conf["htmlBody"]."\r\n";
2823
		$data=$data.$boundaryE."\r\n";
2823
		$data=$data.$boundaryE."\r\n";
2824
		
2824
 
2825
		#如果有設定要上傳附件
2825
		#如果有設定要上傳附件
2826
		if(isset($conf["attachment"])){
2826
		if(isset($conf["attachment"])){
2827
			
2827
 
2828
			#依據每個附件
2828
			#依據每個附件
2829
			for($i=0;$i<count($conf["attachment"]);$i++){
2829
			for($i=0;$i<count($conf["attachment"]);$i++){
2830
				
2830
 
2831
				#初始化寄送附件的語法
2831
				#初始化寄送附件的語法
2832
				$attachment="";
2832
				$attachment="";
2833
				
2833
 
2834
				#確認目標檔案是否存在
2834
				#確認目標檔案是否存在
2835
				#函式說明:檢查多個檔案是否存在
2835
				#函式說明:檢查多個檔案是否存在
2836
				#回傳的結果:
2836
				#回傳的結果:
2837
				#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
2837
				#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
2838
				#$result["error"],錯誤訊息陣列.
2838
				#$result["error"],錯誤訊息陣列.
Line 2846... Line 2846...
2846
				#參考資料來源:
2846
				#參考資料來源:
2847
				#http://php.net/manual/en/function.file-exists.php
2847
				#http://php.net/manual/en/function.file-exists.php
2848
				#http://php.net/manual/en/control-structures.foreach.php
2848
				#http://php.net/manual/en/control-structures.foreach.php
2849
				$checkMutiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
2849
				$checkMutiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
2850
				unset($conf["fileAccess::checkMultiFileExist"]);
2850
				unset($conf["fileAccess::checkMultiFileExist"]);
2851
				
2851
 
2852
				#如果檢查失敗
2852
				#如果檢查失敗
2853
				if($checkMutiFileExist["status"]=="false"){
2853
				if($checkMutiFileExist["status"]=="false"){
2854
					
2854
 
2855
					#設置錯誤識別
2855
					#設置錯誤識別
2856
					$result["status"]="false";
2856
					$result["status"]="false";
2857
 
2857
 
2858
					#設置錯誤資訊
2858
					#設置錯誤資訊
2859
					$result["error"]=$checkMutiFileExist;
2859
					$result["error"]=$checkMutiFileExist;
2860
 
2860
 
2861
					#回傳結果
2861
					#回傳結果
2862
					return $result;
2862
					return $result;
2863
					
2863
 
2864
					}#if end
2864
					}#if end
2865
					
2865
 
2866
				#如果檔案不存在
2866
				#如果檔案不存在
2867
				if($checkMutiFileExist["varExist"][0]=="false"){
2867
				if($checkMutiFileExist["varExist"][0]=="false"){
2868
					
2868
 
2869
					#設置錯誤識別
2869
					#設置錯誤識別
2870
					$result["status"]="false";
2870
					$result["status"]="false";
2871
 
2871
 
2872
					#設置錯誤資訊
2872
					#設置錯誤資訊
2873
					$result["error"]=$checkMutiFileExist;
2873
					$result["error"]=$checkMutiFileExist;
2874
 
2874
 
2875
					#回傳結果
2875
					#回傳結果
2876
					return $result;
2876
					return $result;
2877
					
2877
 
2878
					}#if end
2878
					}#if end
2879
					
2879
 
2880
				#如果是第一個附件
2880
				#如果是第一個附件
2881
				if($i===0){
2881
				if($i===0){
2882
					
2882
 
2883
					#在前面加上 multipart/mixed 的 boundary
2883
					#在前面加上 multipart/mixed 的 boundary
2884
					$data="Content-Type: multipart/mixed; boundary=".$boundary."\r\n\r\n".$data;
2884
					$data="Content-Type: multipart/mixed; boundary=".$boundary."\r\n\r\n".$data;
2885
					
2885
 
2886
					}#if end
2886
					}#if end
2887
					
2887
 
2888
				#如果 $conf["attachmentName"] 不存在
2888
				#如果 $conf["attachmentName"] 不存在
2889
				if(!isset($conf["attachmentName"])){
2889
				if(!isset($conf["attachmentName"])){
2890
					
2890
 
2891
					#涵是說明:
2891
					#涵是說明:
2892
					#取得檔案路徑字串的路徑與檔案的名稱與檔案副檔名
2892
					#取得檔案路徑字串的路徑與檔案的名稱與檔案副檔名
2893
					#回傳的結果:
2893
					#回傳的結果:
2894
					#$result["status"],執行是否正常,"true"正常,"false"代表不正常.
2894
					#$result["status"],執行是否正常,"true"正常,"false"代表不正常.
2895
					#$result["error"],錯誤訊息.
2895
					#$result["error"],錯誤訊息.
Line 2904... Line 2904...
2904
					$conf["fileAccess::getFileAddressAndNameAndFileExtention"]["fileAddressAndName"]=$conf["attachment"][$i];
2904
					$conf["fileAccess::getFileAddressAndNameAndFileExtention"]["fileAddressAndName"]=$conf["attachment"][$i];
2905
					#可省略的參數:
2905
					#可省略的參數:
2906
					#無.
2906
					#無.
2907
					$getFileAddressAndNameAndFileExtention=fileAccess::getFileAddressAndNameAndFileExtention($conf["fileAccess::getFileAddressAndNameAndFileExtention"]);
2907
					$getFileAddressAndNameAndFileExtention=fileAccess::getFileAddressAndNameAndFileExtention($conf["fileAccess::getFileAddressAndNameAndFileExtention"]);
2908
					unset($conf["fileAccess::getFileAddressAndNameAndFileExtention"]);
2908
					unset($conf["fileAccess::getFileAddressAndNameAndFileExtention"]);
2909
					
2909
 
2910
					#如果解析檔案資訊失敗
2910
					#如果解析檔案資訊失敗
2911
					if($getFileAddressAndNameAndFileExtention["status"]==="false"){
2911
					if($getFileAddressAndNameAndFileExtention["status"]==="false"){
2912
						
2912
 
2913
						#設置錯誤識別
2913
						#設置錯誤識別
2914
						$result["status"]="false";
2914
						$result["status"]="false";
2915
 
2915
 
2916
						#設置錯誤資訊
2916
						#設置錯誤資訊
2917
						$result["error"]=$getFileAddressAndNameAndFileExtention;
2917
						$result["error"]=$getFileAddressAndNameAndFileExtention;
2918
 
2918
 
2919
						#回傳結果
2919
						#回傳結果
2920
						return $result;
2920
						return $result;
2921
						
2921
 
2922
						}#if end
2922
						}#if end
2923
					
2923
 
2924
					#設定附件名稱
2924
					#設定附件名稱
2925
					$conf["attachmentName"][$i]=$getFileAddressAndNameAndFileExtention["fullFileName"];
2925
					$conf["attachmentName"][$i]=$getFileAddressAndNameAndFileExtention["fullFileName"];
2926
					
2926
 
2927
					}#if end
2927
					}#if end
2928
					
2928
 
2929
				#反之如果 $conf["attachmentName"][$i] 不存在
2929
				#反之如果 $conf["attachmentName"][$i] 不存在
2930
				else if(!isset($conf["attachmentName"][$i])){
2930
				else if(!isset($conf["attachmentName"][$i])){
2931
					
2931
 
2932
					#涵是說明:
2932
					#涵是說明:
2933
					#取得檔案路徑字串的路徑與檔案的名稱與檔案副檔名
2933
					#取得檔案路徑字串的路徑與檔案的名稱與檔案副檔名
2934
					#回傳的結果:
2934
					#回傳的結果:
2935
					#$result["status"],執行是否正常,"true"正常,"false"代表不正常.
2935
					#$result["status"],執行是否正常,"true"正常,"false"代表不正常.
2936
					#$result["error"],錯誤訊息.
2936
					#$result["error"],錯誤訊息.
Line 2945... Line 2945...
2945
					$conf["fileAccess::getFileAddressAndNameAndFileExtention"]["fileAddressAndName"]=$conf["attachment"][$i];
2945
					$conf["fileAccess::getFileAddressAndNameAndFileExtention"]["fileAddressAndName"]=$conf["attachment"][$i];
2946
					#可省略的參數:
2946
					#可省略的參數:
2947
					#無.
2947
					#無.
2948
					$getFileAddressAndNameAndFileExtention=fileAccess::getFileAddressAndNameAndFileExtention($conf["fileAccess::getFileAddressAndNameAndFileExtention"]);
2948
					$getFileAddressAndNameAndFileExtention=fileAccess::getFileAddressAndNameAndFileExtention($conf["fileAccess::getFileAddressAndNameAndFileExtention"]);
2949
					unset($conf["fileAccess::getFileAddressAndNameAndFileExtention"]);
2949
					unset($conf["fileAccess::getFileAddressAndNameAndFileExtention"]);
2950
					
2950
 
2951
					#如果解析檔案資訊失敗
2951
					#如果解析檔案資訊失敗
2952
					if($getFileAddressAndNameAndFileExtention["status"]=="false"){
2952
					if($getFileAddressAndNameAndFileExtention["status"]=="false"){
2953
						
2953
 
2954
						#設置錯誤識別
2954
						#設置錯誤識別
2955
						$result["status"]="false";
2955
						$result["status"]="false";
2956
 
2956
 
2957
						#設置錯誤資訊
2957
						#設置錯誤資訊
2958
						$result["error"]=$getFileAddressAndNameAndFileExtention;
2958
						$result["error"]=$getFileAddressAndNameAndFileExtention;
2959
 
2959
 
2960
						#回傳結果
2960
						#回傳結果
2961
						return $result;
2961
						return $result;
2962
						
2962
 
2963
						}#if end
2963
						}#if end
2964
					
2964
 
2965
					#設定附件名稱
2965
					#設定附件名稱
2966
					$conf["attachmentName"][$i]=$getFileAddressAndNameAndFileExtention["fullFileName"];
2966
					$conf["attachmentName"][$i]=$getFileAddressAndNameAndFileExtention["fullFileName"];
2967
					
2967
 
2968
					}#if end
2968
					}#if end
2969
					
2969
 
2970
				#如果 $conf["attachmentMimeType"] 不存在
2970
				#如果 $conf["attachmentMimeType"] 不存在
2971
				if(!isset($conf["attachmentMimeType"])){
2971
				if(!isset($conf["attachmentMimeType"])){
2972
					
2972
 
2973
					#設定檔案類型
2973
					#設定檔案類型
2974
					$conf["attachmentMimeType"][$i]="application/*";
2974
					$conf["attachmentMimeType"][$i]="application/*";
2975
					
2975
 
2976
					}#if end
2976
					}#if end
2977
					
2977
 
2978
				#反之如果 $conf["attachmentMimeType"][$i] 不存在	
2978
				#反之如果 $conf["attachmentMimeType"][$i] 不存在
2979
				if(!isset($conf["attachmentMimeType"][$i])){
2979
				if(!isset($conf["attachmentMimeType"][$i])){
2980
					
2980
 
2981
					$conf["attachmentMimeType"][$i]="application/*";
2981
					$conf["attachmentMimeType"][$i]="application/*";
2982
					
2982
 
2983
					}#if end
2983
					}#if end
2984
				
2984
 
2985
				#加上寄送附件的語法
2985
				#加上寄送附件的語法
2986
				$attachment=$attachment.$boundaryS."\r\n";
2986
				$attachment=$attachment.$boundaryS."\r\n";
2987
				$attachment=$attachment."Content-Type: ".$conf["attachmentMimeType"][$i]."; name=".$conf["attachmentName"][$i]."\r\n";
2987
				$attachment=$attachment."Content-Type: ".$conf["attachmentMimeType"][$i]."; name=".$conf["attachmentName"][$i]."\r\n";
2988
				$attachment=$attachment."Content-Disposition: attachment; filename=".$conf["attachmentName"][$i]."\r\n";
2988
				$attachment=$attachment."Content-Disposition: attachment; filename=".$conf["attachmentName"][$i]."\r\n";
2989
				$attachment=$attachment."Content-Transfer-Encoding: base64\r\n";			
2989
				$attachment=$attachment."Content-Transfer-Encoding: base64\r\n";
2990
				$attachment=$attachment."X-Attachment-Id: f_io1ikfii".$i."\r\n";
2990
				$attachment=$attachment."X-Attachment-Id: f_io1ikfii".$i."\r\n";
2991
				
2991
 
2992
				#將檔案用base64加密
2992
				#將檔案用base64加密
2993
				$base64fileStr=base64_encode(file_get_contents($conf["attachment"][$i]));
2993
				$base64fileStr=base64_encode(file_get_contents($conf["attachment"][$i]));
2994
				
2994
 
2995
				#斷行後附加檔案字串
2995
				#斷行後附加檔案字串
2996
				$attachment=$attachment."\r\n".$base64fileStr."\r\n";
2996
				$attachment=$attachment."\r\n".$base64fileStr."\r\n";
2997
				
2997
 
2998
				#如果是最後一個附件
2998
				#如果是最後一個附件
2999
				if($i===count($conf["attachment"])-1){
2999
				if($i===count($conf["attachment"])-1){
3000
				
3000
 
3001
					#混合資料結尾
3001
					#混合資料結尾
3002
					$attachment=$attachment.$boundary."\r\n";
3002
					$attachment=$attachment.$boundary."\r\n";
3003
					
3003
 
3004
					}#if end
3004
					}#if end
3005
				
3005
 
3006
				#增加到信件內文的結尾
3006
				#增加到信件內文的結尾
3007
				$data=$data.$attachment;
3007
				$data=$data.$attachment;
3008
				
3008
 
3009
				}#for end
3009
				}#for end
3010
			
3010
 
3011
			}#if end
3011
			}#if end
3012
		
3012
 
3013
		#body end
3013
		#body end
3014
		
3014
 
3015
		#如果有指定 signWithGPGid
3015
		#如果有指定 signWithGPGid
3016
		if(isset($conf["signWithGPGid"])){
3016
		if(isset($conf["signWithGPGid"])){
3017
		
3017
 
3018
			#將原本的 Content-Type 放到 data 前面.
3018
			#將原本的 Content-Type 放到 data 前面.
3019
			$data=$contentDescInHead.$data;
3019
			$data=$contentDescInHead.$data;
3020
		
3020
 
3021
			#sign之前的內容,要先符合每列不得大於70的字元的規定
3021
			#sign之前的內容,要先符合每列不得大於70的字元的規定
3022
			$data=wordwrap($data,70,"\r\n",true);
3022
			$data=wordwrap($data,70,"\r\n",true);
3023
		
3023
 
3024
			#用gpg指令簽署body
3024
			#用gpg指令簽署body
3025
			#函式說明:
3025
			#函式說明:
3026
			#呼叫shell執行系統命令,並取得回傳的內容.
3026
			#呼叫shell執行系統命令,並取得回傳的內容.
3027
			#回傳結果:
3027
			#回傳結果:
3028
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3028
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
Line 3079... Line 3079...
3079
			#備註:
3079
			#備註:
3080
			#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
3080
			#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
3081
			#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
3081
			#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
3082
			$callShell=external::callShell($conf["external::callShell"]);
3082
			$callShell=external::callShell($conf["external::callShell"]);
3083
			unset($conf["external::callShell"]);
3083
			unset($conf["external::callShell"]);
3084
		
3084
 
3085
			#如果解析檔案資訊失敗
3085
			#如果解析檔案資訊失敗
3086
			if($callShell["status"]==="false"){
3086
			if($callShell["status"]==="false"){
3087
				
3087
 
3088
				#設置錯誤識別
3088
				#設置錯誤識別
3089
				$result["status"]="false";
3089
				$result["status"]="false";
3090
 
3090
 
3091
				#設置錯誤資訊
3091
				#設置錯誤資訊
3092
				$result["error"]=$callShell;
3092
				$result["error"]=$callShell;
3093
 
3093
 
3094
				#回傳結果
3094
				#回傳結果
3095
				return $result;
3095
				return $result;
3096
				
3096
 
3097
				}#if end
3097
				}#if end
3098
				
3098
 
3099
			#如果輸出的內容有異常
3099
			#如果輸出的內容有異常
3100
			if($callShell["output"][0]!=="-----BEGIN PGP SIGNED MESSAGE-----"){
3100
			if($callShell["output"][0]!=="-----BEGIN PGP SIGNED MESSAGE-----"){
3101
			
3101
 
3102
				#設置錯誤識別
3102
				#設置錯誤識別
3103
				$result["status"]="false";
3103
				$result["status"]="false";
3104
 
3104
 
3105
				#設置錯誤資訊
3105
				#設置錯誤資訊
3106
				$result["error"]=$callShell;
3106
				$result["error"]=$callShell;
3107
 
3107
 
3108
				#回傳結果
3108
				#回傳結果
3109
				return $result;
3109
				return $result;
3110
			
3110
 
3111
				}#if end
3111
				}#if end
3112
				
3112
 
3113
			#如果簽署所用的方式不是SHA512
3113
			#如果簽署所用的方式不是SHA512
3114
			if($callShell["output"][1]!=="Hash: SHA512"){
3114
			if($callShell["output"][1]!=="Hash: SHA512"){
3115
			
3115
 
3116
				#設置錯誤識別
3116
				#設置錯誤識別
3117
				$result["status"]="false";
3117
				$result["status"]="false";
3118
 
3118
 
3119
				#設置錯誤資訊
3119
				#設置錯誤資訊
3120
				$result["error"]=$callShell;
3120
				$result["error"]=$callShell;
3121
 
3121
 
3122
				#回傳結果
3122
				#回傳結果
3123
				return $result;
3123
				return $result;
3124
			
3124
 
3125
				}#if end
3125
				}#if end
3126
				
3126
 
3127
			#預設的 pgp 簽署方式
3127
			#預設的 pgp 簽署方式
3128
			$micalg="micalg=\"pgp-sha512\"";
3128
			$micalg="micalg=\"pgp-sha512\"";
3129
		
3129
 
3130
			#如果輸出結尾不是 "-----END PGP SIGNATURE-----"
3130
			#如果輸出結尾不是 "-----END PGP SIGNATURE-----"
3131
			if($callShell["output"][count($callShell["output"])-1]!=="-----END PGP SIGNATURE-----"){
3131
			if($callShell["output"][count($callShell["output"])-1]!=="-----END PGP SIGNATURE-----"){
3132
			
3132
 
3133
				#設置錯誤識別
3133
				#設置錯誤識別
3134
				$result["status"]="false";
3134
				$result["status"]="false";
3135
 
3135
 
3136
				#設置錯誤資訊
3136
				#設置錯誤資訊
3137
				$result["error"]=$callShell;
3137
				$result["error"]=$callShell;
3138
 
3138
 
3139
				#回傳結果
3139
				#回傳結果
3140
				return $result;
3140
				return $result;
3141
			
3141
 
3142
				}#if end
3142
				}#if end
3143
				
3143
 
3144
			#初始化儲存  PGP SIGNATURE 字串
3144
			#初始化儲存  PGP SIGNATURE 字串
3145
			$signDataOfGPG="";	
3145
			$signDataOfGPG="";
3146
				
3146
 
3147
			#尚未到開始 PGP SIGNATURE 部分時
3147
			#尚未到開始 PGP SIGNATURE 部分時
3148
			while($callShell["output"][count($callShell["output"])-1]!=="-----BEGIN PGP SIGNATURE-----"){
3148
			while($callShell["output"][count($callShell["output"])-1]!=="-----BEGIN PGP SIGNATURE-----"){
3149
			
3149
 
3150
				#如果有資料了
3150
				#如果有資料了
3151
				if(!empty($signDataOfGPG)){
3151
				if(!empty($signDataOfGPG)){
3152
				
3152
 
3153
					#前面加上換行字元
3153
					#前面加上換行字元
3154
					$signDataOfGPG="\r\n".$signDataOfGPG;
3154
					$signDataOfGPG="\r\n".$signDataOfGPG;
3155
				
3155
 
3156
					}#if end
3156
					}#if end
3157
			
3157
 
3158
				#取得 PGP SIGNATURE 部分
3158
				#取得 PGP SIGNATURE 部分
3159
				$signDataOfGPG=$callShell["output"][count($callShell["output"])-1].$signDataOfGPG;
3159
				$signDataOfGPG=$callShell["output"][count($callShell["output"])-1].$signDataOfGPG;
3160
			
3160
 
3161
				#移除已經抓好的資料
3161
				#移除已經抓好的資料
3162
				unset($callShell["output"][count($callShell["output"])-1]);
3162
				unset($callShell["output"][count($callShell["output"])-1]);
3163
			
3163
 
3164
				}#while end
3164
				}#while end
3165
				
3165
 
3166
			#取得 PGP SIGNATURE 部分
3166
			#取得 PGP SIGNATURE 部分
3167
			$signDataOfGPG="\r\n".$callShell["output"][count($callShell["output"])-1]."\r\n".$signDataOfGPG;
3167
			$signDataOfGPG="\r\n".$callShell["output"][count($callShell["output"])-1]."\r\n".$signDataOfGPG;
3168
			
3168
 
3169
			#head 增加表示有 GPG 簽署
3169
			#head 增加表示有 GPG 簽署
3170
			$head=$head."Security: GPG signed"."\r\n";
3170
			$head=$head."Security: GPG signed"."\r\n";
3171
		
3171
 
3172
			#函式說明:
3172
			#函式說明:
3173
			#建立以圖片(PNG格式)呈現的驗證碼.
3173
			#建立以圖片(PNG格式)呈現的驗證碼.
3174
			#回傳的解果:
3174
			#回傳的解果:
3175
			#$result["status"],執行是否正常,"true"代表執行成功,"false"代表執行失敗.
3175
			#$result["status"],執行是否正常,"true"代表執行成功,"false"代表執行失敗.
3176
			#$result["error"],錯誤訊息.
3176
			#$result["error"],錯誤訊息.
Line 3198... Line 3198...
3198
			#無.
3198
			#無.
3199
			#備註:
3199
			#備註:
3200
			#無.
3200
			#無.
3201
			$validationCode=authenticate::validationCode($conf["authenticate::validationCode"]);
3201
			$validationCode=authenticate::validationCode($conf["authenticate::validationCode"]);
3202
			unset($conf["authenticate::validationCode"]);
3202
			unset($conf["authenticate::validationCode"]);
3203
			
3203
 
3204
			#如果檢查失敗
3204
			#如果檢查失敗
3205
			if($validationCode["status"]==="false"){
3205
			if($validationCode["status"]==="false"){
3206
				
3206
 
3207
				#設置錯誤識別
3207
				#設置錯誤識別
3208
				$result["status"]="false";
3208
				$result["status"]="false";
3209
				
3209
 
3210
				#設置錯誤訊息
3210
				#設置錯誤訊息
3211
				$result["error"]=$validationCode;
3211
				$result["error"]=$validationCode;
3212
				
3212
 
3213
				#回傳結果
3213
				#回傳結果
3214
				return $result;
3214
				return $result;
3215
				
3215
 
3216
				}#if end
3216
				}#if end
3217
			
3217
 
3218
			#初始化 boundary
3218
			#初始化 boundary
3219
			$boundary=$validationCode["randNumberWord"];
3219
			$boundary=$validationCode["randNumberWord"];
3220
					
3220
 
3221
			#初始化 boundary start
3221
			#初始化 boundary start
3222
			$boundaryS="--".$boundary;
3222
			$boundaryS="--".$boundary;
3223
			
3223
 
3224
			#初始化 boundary end
3224
			#初始化 boundary end
3225
			$boundaryE=$boundaryS."--";
3225
			$boundaryE=$boundaryS."--";
3226
		
3226
 
3227
			#將 data 用新的 boundary 包起來
3227
			#將 data 用新的 boundary 包起來
3228
			$data=$boundaryS."\r\n".$data."\r\n";
3228
			$data=$boundaryS."\r\n".$data."\r\n";
3229
			
3229
 
3230
			#8個空格
3230
			#8個空格
3231
			$eightSpace="        ";
3231
			$eightSpace="        ";
3232
			
3232
 
3233
			#描述內容為 gpg key 簽署的 head 資訊,"protocol"要空8格
3233
			#描述內容為 gpg key 簽署的 head 資訊,"protocol"要空8格
3234
			$gpgData="Content-Type: multipart/signed; ".$micalg.";"."\r\n".$eightSpace."protocol=\"application/pgp-signature\"; boundary=\"".$boundary."\"\r\n";
3234
			$gpgData="Content-Type: multipart/signed; ".$micalg.";"."\r\n".$eightSpace."protocol=\"application/pgp-signature\"; boundary=\"".$boundary."\"\r\n";
3235
			
3235
 
3236
			#增加描述用於 sign 的 gpg pub key 
3236
			#增加描述用於 sign 的 gpg pub key
3237
			$signDataOfGPG="Content-Type: application/pgp-signature; name=\"signature.asc\""."\r\n"."Content-Description: This is a digitally signed message part"."\r\n".$signDataOfGPG."\r\n";
3237
			$signDataOfGPG="Content-Type: application/pgp-signature; name=\"signature.asc\""."\r\n"."Content-Description: This is a digitally signed message part"."\r\n".$signDataOfGPG."\r\n";
3238
			
3238
 
3239
			#設置gpg key簽署的資訊
3239
			#設置gpg key簽署的資訊
3240
			$data=$data.$boundaryS."\r\n".$signDataOfGPG."\r\n".$boundaryE."\r\n";
3240
			$data=$data.$boundaryS."\r\n".$signDataOfGPG."\r\n".$boundaryE."\r\n";
3241
			
3241
 
3242
			#取得放置於head的Contet-Type描述
3242
			#取得放置於head的Contet-Type描述
3243
			$contentDescInHead=&$gpgData;
3243
			$contentDescInHead=&$gpgData;
3244
			
3244
 
3245
			}#if end
3245
			}#if end
3246
			
3246
 
3247
		#組合head與body,依據規定,每列不得大於70的字元
3247
		#組合head與body,依據規定,每列不得大於70的字元
3248
		$data=wordwrap($head.$contentDescInHead.$data,70,"\r\n",true);
3248
		$data=wordwrap($head.$contentDescInHead.$data,70,"\r\n",true);
3249
		
3249
 
3250
		#Send the DATA command to start message body
3250
		#Send the DATA command to start message body
3251
		if(\PEAR::isError($smtp->data($data))){
3251
		if(\PEAR::isError($smtp->data($data))){
3252
			
3252
 
3253
			#設置錯誤識別
3253
			#設置錯誤識別
3254
			$result["status"]="false";
3254
			$result["status"]="false";
3255
		
3255
 
3256
			#設置錯誤訊息
3256
			#設置錯誤訊息
3257
			$result["error"]="Unable to send data:".$data;
3257
			$result["error"]="Unable to send data:".$data;
3258
		
3258
 
3259
			#回傳結果
3259
			#回傳結果
3260
			return $result;
3260
			return $result;
3261
			
3261
 
3262
			}#if end
3262
			}#if end
3263
		
3263
 
3264
		#使用完畢後要關閉連線
3264
		#使用完畢後要關閉連線
3265
		$smtp->disconnect();
3265
		$smtp->disconnect();
3266
		
3266
 
3267
		#設置執行正常
3267
		#設置執行正常
3268
		$result["status"]="true";
3268
		$result["status"]="true";
3269
		
3269
 
3270
		#回傳結果
3270
		#回傳結果
3271
		return $result;
3271
		return $result;
3272
		
3272
 
3273
		}#function pear_smtp_send end
3273
		}#function pear_smtp_send end
3274
	
3274
 
3275
	}#class mail end
3275
	}#class mail end
3276
	
-
 
3277
?>
-
 
3278
3276
 
-
 
3277
?>
-
 
3278