Subversion Repositories php-qbpwcf

Rev

Rev 237 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
3 liveuser 1
<?php
2
 
3
/*
4
 
5
	QBPWCF, Quick Build PHP website Component base on Fedora Linux.
239 liveuser 6
    Copyright (C) 2014~2026 MIN ZHI, CHEN
3 liveuser 7
 
8
    This file is part of QBPWCF.
9
 
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
12
    the Free Software Foundation, either version 3 of the License, or
13
    (at your option) any later version.
14
 
15
    QBPWCF is distributed in the hope that it will be useful,
16
    but WITHOUT ANY WARRANTY; without even the implied warranty of
17
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
    GNU General Public License for more details.
19
 
20
    You should have received a copy of the GNU General Public License
21
    along with QBPWCF.  If not, see <http://www.gnu.org/licenses/>.
22
 
23
*/
24
namespace qbpwcf;
25
 
26
/*
27
類別說明:
28
跟E-Mail應用有關的類別.
29
備註:
30
無.
31
*/
32
class mail{
33
 
34
	/*
35
	#函式說明:
36
	#當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.
37
	#回傳結果:
38
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
39
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
40
	#$result["function"],當前執行的函式名稱.
41
	#必填參數:
42
	#$method,物件,為物件實體或類別名稱,會自動置入該參數.
43
	#$arguments,陣列,為呼叫方法時所用的參數.
44
	#可省略參數:
45
	#無.
46
	#參考資料:
47
	#__call=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
48
	#備註:
49
	#無.
50
	*/
51
	public function __call($method,$arguments){
226 liveuser 52
 
3 liveuser 53
		#取得當前執行的函式
54
		$result["function"]=__FUNCTION__;
226 liveuser 55
 
3 liveuser 56
		#設置執行不正常
57
		$result["status"]="false";
226 liveuser 58
 
3 liveuser 59
		#設置執行錯誤
60
		$result["error"][]=__NAMESPACE__ ."/".$method."() 不存在!";
226 liveuser 61
 
3 liveuser 62
		#設置所丟入的參數
63
		$result["error"][]=$arguments;
226 liveuser 64
 
3 liveuser 65
		#回傳結果
66
		return $result;
226 liveuser 67
 
3 liveuser 68
		}#function __call end
226 liveuser 69
 
3 liveuser 70
	/*
71
	#函式說明:
72
	#當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.
73
	#回傳結果:
74
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
75
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
76
	#$result["function"],當前執行的函式名稱.
77
	#必填參數:
78
	#$method,物件,為物件實體或類別名稱,會自動置入該參數.
79
	#$arguments,陣列,為呼叫方法時所用的參數.
80
	#可省略參數:
81
	#無.
82
	#參考資料:
83
	#__call=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
84
	#備註:
85
	#無.
86
	*/
87
	public static function __callStatic($method,$arguments){
226 liveuser 88
 
3 liveuser 89
		#取得當前執行的函式
90
		$result["function"]=__FUNCTION__;
226 liveuser 91
 
3 liveuser 92
		#設置執行不正常
93
		$result["status"]="false";
226 liveuser 94
 
3 liveuser 95
		#設置執行錯誤
96
		$result["error"][]="欲呼叫的". __NAMESPACE__ ."/".$method."() 不存在!";
226 liveuser 97
 
3 liveuser 98
		#設置所丟入的參數
99
		$result["error"][]=$arguments;
226 liveuser 100
 
3 liveuser 101
		#回傳結果
102
		return $result;
226 liveuser 103
 
3 liveuser 104
		}#function __callStatic end
226 liveuser 105
 
3 liveuser 106
	/*
107
	#函式說明:
108
	#登入 imap 信箱
109
	#回傳結果:
110
	#$result["status"],寄信的情況,若爲"true",則十之八九沒有問題.
111
	#$result["error"],錯誤訊息陣列
112
	#$result["function"],當前執行的函數
113
	#$result["content"],執行imap_open()的回傳內容
114
	#必填參數:
115
	$conf["username"]="";#使用者帳戶
116
	$conf["password"]="";#使用者密碼
117
	#可省略參數:
118
	#$conf["mailServerPositionAndPort"]="";#信箱伺服器的網址與連接口,若省略則採用預設的gmail信箱
119
	#參考資料:
120
	#http://www.php.net/manual/en/function.imap-open.php
121
	#http://davidwalsh.name/gmail-php-imap
122
	#https://support.google.com/mail/troubleshooter/1668960?rd=1#ts=1665018,1665144
123
	#備註:
124
	#無.
125
	*/
126
	public static function imapLogin(&$conf){
127
 
128
		#初始化要回傳的結果
129
		$result=array();
130
 
131
		#儲存當前執行的函數
132
		$result["function"]=__FUNCTION__;
133
 
134
		#如果 $conf 不為陣列
135
		if(gettype($conf)!="array"){
226 liveuser 136
 
3 liveuser 137
			#設置執行失敗
138
			$result["status"]="false";
226 liveuser 139
 
3 liveuser 140
			#設置執行錯誤訊息
141
			$result["error"][]="\$conf變數須為陣列形態";
142
 
143
			#如果傳入的參數為 null
144
			if($conf==null){
226 liveuser 145
 
3 liveuser 146
				#設置執行錯誤訊息
147
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 148
 
3 liveuser 149
				}#if end
150
 
151
			#回傳結果
152
			return $result;
226 liveuser 153
 
3 liveuser 154
			}#if end
226 liveuser 155
 
3 liveuser 156
		#檢查參數
157
		#函式說明:
158
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
159
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
160
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
161
		#$result["function"],當前執行的函式名稱.
162
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
163
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
164
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
165
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
166
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
167
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
168
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
169
		#必填寫的參數:
170
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
171
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
172
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
173
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("username","password");
226 liveuser 174
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
3 liveuser 175
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
176
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
177
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
178
		#可以省略的參數:
179
		#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
180
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
181
		#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
182
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("mailServerPositionAndPort");
226 liveuser 183
		#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 184
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
185
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
186
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("imap.gmail.com:993");
187
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
188
		#$conf["arrayCountEqualCheck"][]=array();
189
		#參考資料來源:
190
		#array_keys=>http://php.net/manual/en/function.array-keys.php
191
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
192
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 193
 
3 liveuser 194
		#如果檢查失敗
195
		if($checkArguments["status"]=="false"){
226 liveuser 196
 
3 liveuser 197
			#設置錯誤識別
198
			$result["status"]="false";
226 liveuser 199
 
3 liveuser 200
			#設置錯誤訊息
201
			$result["error"]=$checkArguments;
226 liveuser 202
 
3 liveuser 203
			#回傳結果
204
			return $result;
226 liveuser 205
 
3 liveuser 206
			}#if end
226 liveuser 207
 
3 liveuser 208
		#如果檢查不通過
209
		if($checkArguments["passed"]=="false"){
226 liveuser 210
 
3 liveuser 211
			#設置錯誤識別
212
			$result["status"]="false";
226 liveuser 213
 
3 liveuser 214
			#設置錯誤訊息
215
			$result["error"]=$checkArguments;
226 liveuser 216
 
3 liveuser 217
			#回傳結果
218
			return $result;
226 liveuser 219
 
3 liveuser 220
			}#if end
221
 
222
		#To connect to an SSL IMAP or POP3 server, add /ssl after the protocol
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());
225
 
226
		#如果 imap_open() 執行失敗
227
		if($mbox["status"]==false){
226 liveuser 228
 
3 liveuser 229
			#設置執行不正常
230
			$result["status"]="false";
226 liveuser 231
 
3 liveuser 232
			#設置錯誤訊息
233
			$result["error"]=\imap_last_error();
226 liveuser 234
 
3 liveuser 235
			}#if end
236
 
237
		#儲存執行 imap_open() 後的 resource
238
		$result["content"]=$mbox;
239
 
240
		#設置執行正常
241
		$result["status"]="true";
242
 
243
		#回傳連結訊息
244
		return $result;
245
 
246
		}#function imapLogin end
247
 
248
	/*
249
	#函式說明:
250
	#登出信箱
251
	#$result["status"],寄信的情況,若爲"true",則十之八九沒有問題.
252
	#$result["error"],錯誤訊息陣列
253
	#$result["function"],當前執行的函數
254
	#必填參數:
255
	#$conf["mailConnection"],字串,連結到mailServer的資訊
256
	$conf["mailConnection"]="";
257
	#可省略參數:
258
	#無.
259
	#參考資料:
260
	#http://www.php.net/manual/en/function.imap-open.php
261
	#http://davidwalsh.name/gmail-php-imap
262
	#備註:
263
	#無.
264
	*/
265
	public static function imapLogout(&$conf){
266
 
267
		#初始化要回傳的結果
268
		$result=array();
269
 
270
		#儲存當前執行的函數
271
		$result["function"]=__FUNCTION__;
272
 
273
		#如果 $conf 不為陣列
274
		if(gettype($conf)!="array"){
226 liveuser 275
 
3 liveuser 276
			#設置執行失敗
277
			$result["status"]="false";
226 liveuser 278
 
3 liveuser 279
			#設置執行錯誤訊息
280
			$result["error"][]="\$conf變數須為陣列形態";
281
 
282
			#如果傳入的參數為 null
283
			if($conf==null){
226 liveuser 284
 
3 liveuser 285
				#設置執行錯誤訊息
286
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 287
 
3 liveuser 288
				}#if end
289
 
290
			#回傳結果
291
			return $result;
226 liveuser 292
 
3 liveuser 293
			}#if end
226 liveuser 294
 
3 liveuser 295
		#檢查參數
296
		#函式說明:
297
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
298
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
299
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
300
		#$result["function"],當前執行的函式名稱.
301
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
302
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
303
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
304
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
305
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
306
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
307
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
308
		#必填寫的參數:
309
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
310
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
311
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
312
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("mailConnection");
226 liveuser 313
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
3 liveuser 314
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("resource");
315
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
316
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
317
		#可以省略的參數:
318
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
319
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
320
		#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
321
		#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("mailServerPositionAndPort");
226 liveuser 322
		#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 323
		#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
324
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
325
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("imap.gmail.com:993");
326
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
327
		#$conf["arrayCountEqualCheck"][]=array();
328
		#參考資料來源:
329
		#array_keys=>http://php.net/manual/en/function.array-keys.php
330
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
331
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 332
 
3 liveuser 333
		#如果檢查失敗
334
		if($checkArguments["status"]=="false"){
226 liveuser 335
 
3 liveuser 336
			#設置錯誤識別
337
			$result["status"]="false";
226 liveuser 338
 
3 liveuser 339
			#設置錯誤訊息
340
			$result["error"]=$checkArguments;
226 liveuser 341
 
3 liveuser 342
			#回傳結果
343
			return $result;
226 liveuser 344
 
3 liveuser 345
			}#if end
226 liveuser 346
 
3 liveuser 347
		#如果檢查不通過
348
		if($checkArguments["passed"]=="false"){
226 liveuser 349
 
3 liveuser 350
			#設置錯誤識別
351
			$result["status"]="false";
226 liveuser 352
 
3 liveuser 353
			#設置錯誤訊息
354
			$result["error"]=$checkArguments;
226 liveuser 355
 
3 liveuser 356
			#回傳結果
357
			return $result;
226 liveuser 358
 
3 liveuser 359
			}#if end
360
 
361
		#如果中斷與mailServer的連線失敗
362
		if(\imap_close($conf["mailConnection"])==false){
226 liveuser 363
 
3 liveuser 364
			#設置執行不正常
365
			$result["status"]="false";
226 liveuser 366
 
3 liveuser 367
			#設置錯誤訊息
368
			$result["error"][]="中斷與 imap Server 的連線失敗";
226 liveuser 369
 
3 liveuser 370
			#回傳結果
371
			return $result;
226 liveuser 372
 
3 liveuser 373
			}#if end
226 liveuser 374
 
3 liveuser 375
		#設置執行正常
376
		$result["status"]="true";
226 liveuser 377
 
3 liveuser 378
		#回傳結果
379
		return $result;
380
 
381
		}#function imapLogout end
382
 
383
	/*
384
	#函式說明:
385
	#用imap協定寄信
386
	#回傳結果:
387
	#$result["status"],寄信的情況,"true"爲成功,"false"爲失敗.
388
	#$result["error"],錯誤訊息陣列
389
	#$result["function"],當前執行的函數
390
	#必填參數:
391
	$conf["username"]="";#郵件服務的登入帳號
392
	$conf["password"]="";#郵件服務的登入密碼
393
	$conf["receiver"]="";#收件着
394
	$conf["subject"]="";#信件主旨
395
	$conf["body"]="";#本文
396
	#可省略參數:
397
	#$conf["mailServerPositionAndPort"]="";#郵件伺服器的網址與連接口,若省略則採用預設的gmail信箱
398
	#$conf["headerInfo"]="";#表頭訊息,預設爲"From:".$conf["username"]."\r\n"."Reply-To:".$conf["receiver"]."\r\n";
399
	#$conf["cc"]="";#信件的副本要寄給誰
400
	#$conf["bcc"]="";#信件的密件副本要寄給誰,預設爲$conf["username"],以作爲備份。
401
	#參考資料:
402
	#http://www.php.net/manual/en/function.imap-mail.php
403
	#http://www.php.net/manual/en/function.imap-errors.php
404
	#http://www.php.net/manual/en/function.imap-alerts.php
405
	#http://www.php.net/manual/en/function.imap-last-error.php
406
	#http://wiki.dreamhost.com/PHP_IMAP#Verify_PHP_INI_Settings
407
	#備註:
408
	#需要php-imap套件
409
	#無法寄送成功?
226 liveuser 410
	*/
3 liveuser 411
	public static function mailTo(&$conf){
412
 
413
		#初始化要回傳的結果
414
		$result=array();
415
 
416
		#儲存當前執行的函數
417
		$result["function"]=__FUNCTION__;
418
 
419
		#如果 $conf 不為陣列
420
		if(gettype($conf)!="array"){
226 liveuser 421
 
3 liveuser 422
			#設置執行失敗
423
			$result["status"]="false";
226 liveuser 424
 
3 liveuser 425
			#設置執行錯誤訊息
426
			$result["error"][]="\$conf變數須為陣列形態";
427
 
428
			#如果傳入的參數為 null
429
			if($conf==null){
226 liveuser 430
 
3 liveuser 431
				#設置執行錯誤訊息
432
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 433
 
3 liveuser 434
				}#if end
435
 
436
			#回傳結果
437
			return $result;
226 liveuser 438
 
3 liveuser 439
			}#if end
226 liveuser 440
 
3 liveuser 441
		#檢查參數
442
		#函式說明:
443
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
444
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
445
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
446
		#$result["function"],當前執行的函式名稱.
447
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
448
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
449
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
450
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
451
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
452
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
453
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
454
		#必填寫的參數:
455
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
456
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
457
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
458
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("username","password","receiver","subject","body");
226 liveuser 459
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
3 liveuser 460
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string","string","string");
461
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
462
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
463
		#可以省略的參數:
464
		#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
465
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
466
		#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
467
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("mailServerPositionAndPort","headerInfo","cc","bcc");
226 liveuser 468
		#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 469
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","string");
470
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
471
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,null,null,"\$conf[\"username\"]");
472
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
473
		#$conf["arrayCountEqualCheck"][]=array();
474
		#參考資料來源:
475
		#array_keys=>http://php.net/manual/en/function.array-keys.php
476
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
477
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 478
 
3 liveuser 479
		#如果檢查失敗
480
		if($checkArguments["status"]=="false"){
226 liveuser 481
 
3 liveuser 482
			#設置錯誤識別
483
			$result["status"]="false";
226 liveuser 484
 
3 liveuser 485
			#設置錯誤訊息
486
			$result["error"]=$checkArguments;
226 liveuser 487
 
3 liveuser 488
			#回傳結果
489
			return $result;
226 liveuser 490
 
3 liveuser 491
			}#if end
226 liveuser 492
 
3 liveuser 493
		#如果檢查不通過
494
		if($checkArguments["passed"]=="false"){
226 liveuser 495
 
3 liveuser 496
			#設置錯誤識別
497
			$result["status"]="false";
226 liveuser 498
 
3 liveuser 499
			#設置錯誤訊息
500
			$result["error"]=$checkArguments;
226 liveuser 501
 
3 liveuser 502
			#回傳結果
503
			return $result;
226 liveuser 504
 
3 liveuser 505
			}#if end
506
 
507
		#函式說明:
508
		#登入信箱
509
		#回傳結果:
510
		#$result,連結mail的訊息。
511
		#必填參數:
512
		$conf["mail"]["login"]["username"]=$conf["username"];#使用者帳戶
513
		$conf["mail"]["login"]["password"]=$conf["password"];#使用者密碼
514
		#可省略參數:
515
 
516
		#若 $conf["mail"]["login"]["mailServerPositionAndPort"] 沒有設置,則預設爲gmail信箱
517
		if(!isset($conf["mail"]["login"]["mailServerPositionAndPort"])){
226 liveuser 518
 
3 liveuser 519
			$conf["mail"]["login"]["mailServerPositionAndPort"]="imap.gmail.com:993";
520
 
521
			}#if end
522
 
523
		#反之有設定,則採用指定值
524
		else{
525
 
526
			$conf["mail"]["login"]["mailServerPositionAndPort"]=$conf["mailServerPositionAndPort"];
527
 
528
			}#else end
529
 
530
		#$conf["mailServerPositionAndPort"]="";#信箱伺服器的網址與連接口,若省略則採用預設的gmail信箱
531
		#參考資料來源:
532
		#http://www.php.net/manual/en/function.imap-open.php
533
		#http://davidwalsh.name/gmail-php-imap
534
		$mailConnection=mail::imapLogin($conf["mail"]["login"]);
535
		unset($conf["mail"]["login"]);
536
 
537
		#如果登入imap伺服器失敗
538
		if($mailConnection["status"]=="false"){
226 liveuser 539
 
3 liveuser 540
			#設置錯誤訊息
541
			$result["error"]=$mailConnection;
226 liveuser 542
 
3 liveuser 543
			#設置執行失敗
544
			$result["status"]="false";
226 liveuser 545
 
3 liveuser 546
			#回傳結果
547
			return $result;
226 liveuser 548
 
3 liveuser 549
			}#if end
550
 
551
		#如果 $conf["headerInfo"] 沒有指定
552
		if(!isset($conf["headerInfo"])){
553
 
554
			$conf["headerInfo"]="From:".$conf["username"]."\r\n"."Reply-To:".$conf["receiver"]."\r\n";
555
 
556
			}#if end
557
 
558
		#如果 $conf["cc"] 沒有設定
559
		if(!isset($conf["cc"])){
560
 
561
			#則設爲null
562
			$conf["cc"]=null;
563
 
564
			}#if end
565
 
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"]));
226 liveuser 568
 
3 liveuser 569
		#取得使用imap服務與到的警示訊息
570
		$result["imapAlerts"]=\imap_alerts();
571
 
572
		#取得使用imap服務與到的錯誤訊息
573
		$result["imapErrors"]=\imap_errors();
574
 
575
		#取得使用imap服務與到的最新錯誤訊息
576
		$result["imapLastErrors"]=\imap_last_error();
577
 
578
		#函式說明:
579
		#登出信箱
580
		#必填參數
581
		$conf["mail"]["logout"]["mailConnection"]=$mailConnection["content"];#連結到mailServer的資訊
582
		#參考資料來源:
583
		#http:#www.php.net/manual/en/function.imap-open.php
584
		#http:#davidwalsh.name/gmail-php-imap
585
		$imapLogout=mail::imapLogout($conf["mail"]["logout"]);
586
		unset($conf["mail"]["logout"]);
587
 
588
		#如果登出imap伺服器失敗
589
		if($imapLogout["status"]=="false"){
226 liveuser 590
 
3 liveuser 591
			#設置執行失敗
592
			$result["status"]="false";
226 liveuser 593
 
3 liveuser 594
			#設置錯誤訊息
595
			$result["error"]=$imapLogout;
226 liveuser 596
 
3 liveuser 597
			#回傳結果
598
			return $result;
226 liveuser 599
 
3 liveuser 600
			}#if end
601
 
602
		#設置執行正常
603
		$result["status"]="true";
604
 
605
		#回傳寄信的結果
606
		return $result;
607
 
608
		}#function mailTo end
609
 
610
	/*
611
	#函式說明:
612
	#使用 curl 來透過SMTP伺服器寄信
613
	#回傳結果:
614
	#$result["status"],寄信的情況,若爲"true",則十之八九沒有問題.
615
	#$result["error"],錯誤訊息陣列
616
	#$result["function"],當前執行的函數
617
	#$result["warning"],警示訊息,一些不會導致失敗但不能說是完美的問題.
618
	#$result["cmd"],寄信的指令.
619
	#$result["detailCmd"],較詳細的寄信指令.
620
	#必填參數:
621
	#$conf["username"],字串,用來登入郵件伺服器的帳號
622
	$conf["username"]="";
623
	#$conf["password"],字串,用來登入郵件伺服器的密碼
624
	$conf["password"]="";
625
	#$conf["receiverMail"],陣列,收件人的信箱
626
	$conf["receiverMail"]=array("");
627
	#$conf["subject"],字串,郵件的主題
628
	$conf["subject"]="";
629
	#$conf["plainBody"],字串,郵件本文的純文字內容.
630
	$conf["plainBody"]="";
631
	#$conf["htmlBody"]="";,字串,郵件本文的html內容,多媒體盡量不要用base64的方式來嵌入,因為大部分的郵件服務(Gmail)都不支援,如果是在單機上的郵件軟體就可能有支援,例如:Evolution.
632
	$conf["htmlBody"]="";
633
	#$conf["fileArgu"],字串,php內建變數「__FILE__」的內容.
634
	$conf["fileArgu"]=__FILE__;
635
	#可省略參數:
636
	#$conf["mailServer"],字串,要使用的SMTP郵件伺服器網址與連接口,預設爲 smtps://smtp.gmail.com:465
637
	#$conf["mailServer"]="";
638
	#$conf["mailerMailDisplay"],字串,要顯示的寄件人信箱,預設爲 $conf["username"]
639
	#$conf["mailerMailDisplay"]="";
640
	#$conf["mailerNameDisplay"],字串,要顯示的寄件人姓名,預設爲 $conf["username"]
641
	#$conf["mailerNameDisplay"]="";
642
	#$conf["receiverMailDisplay"],陣列,要顯示的收件人信箱,預設爲 $conf["receiverMail"] 對應的元素.
643
	#$conf["receiverMailDisplay"]="";#
644
	#$conf["receiverNameDisplay"],陣列,要顯示的收件人姓名,預設爲 $conf["receiverMail"] 對應的元素.
645
	#$conf["receiverNameDisplay"]="";
646
	#$conf["attachment"],陣列,每個要寄送的附件路徑與檔案名稱
647
	#$conf["attachment"]=array();
648
	#$conf["attachmentName"],陣列,每個要寄送的附件顯示名稱,預設為$conf["attachment"]中的實際檔案名稱.
649
	#$conf["attachmentName"]=array();
650
	#$conf["attachmentMimeType"],陣列,每個附件的 mimeType,預設為"application/*".
651
	#$conf["attachmentMimeType"]array();
652
	#$conf["levelForCheckSSL"],"字串",預設為"force",代表ssl一定要符合規範,"loose"代表先嘗試ssl要符合規範,若不符合則第2次就允許不符合規範的ssl,"none"代表直接允許不符合規範的ssl.
653
	#$conf["levelForCheckSSL"]="";
654
	#範例語句:
655
	#curl --url smtps://smtp.gmail.com:465 -u username@gmail.com:userPassword --mail-from username@gmail.com --mail-rcpt receiver@mail.com --upload-file mail.txt -v
656
	#範例信件內容:
657
	#From: "userName" <username@gmail.com>
658
	#To: "receiverName" <userPassword@yahoo.com.tw>
659
	#Subject: This is a test
660
	#本文~
661
	#參考資料:
662
	#用curl來寄信=>http://stackoverflow.com/questions/14722556/using-curl-to-send-email
663
	#降低安全性標準讓curl可以使用=>https://www.google.com/settings/security/lesssecureapps
664
	#信件內容header的設定=>http://jjdai.zhupiter.com/2010/10/php-%E5%A6%82%E4%BD%95%E5%82%B3%E9%80%81%E4%B8%80%E5%B0%81-mime-html-%E6%A0%BC%E5%BC%8F%E7%9A%84-email-%E4%BF%A1%E4%BB%B6/
665
	#檔案每列不得超超過70個字元=>http://php.net/manual/en/function.mail.php
666
	#寄信給多人=>https://github.com/curl/curl/issues/784
667
	#備註:
48 liveuser 668
	#Fedora42提供的curl指令不支援smtp協定,需要置換libcurl-minimal為libcurl.
3 liveuser 669
	*/
670
	public static function curlSmtp(&$conf){
671
 
672
		#初始化要回傳的結果
673
		$result=array();
674
 
675
		#儲存當前執行的函數
676
		$result["function"]=__FUNCTION__;
677
 
678
		#如果 $conf 不為陣列
679
		if(gettype($conf)!="array"){
226 liveuser 680
 
3 liveuser 681
			#設置執行失敗
682
			$result["status"]="false";
226 liveuser 683
 
3 liveuser 684
			#設置執行錯誤訊息
685
			$result["error"][]="\$conf變數須為陣列形態";
686
 
687
			#如果傳入的參數為 null
688
			if($conf==null){
226 liveuser 689
 
3 liveuser 690
				#設置執行錯誤訊息
691
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 692
 
3 liveuser 693
				}#if end
694
 
695
			#回傳結果
696
			return $result;
226 liveuser 697
 
3 liveuser 698
			}#if end
226 liveuser 699
 
3 liveuser 700
		#檢查參數
701
		#函式說明:
702
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
703
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
704
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
705
		#$result["function"],當前執行的函式名稱.
706
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
707
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
708
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
709
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
710
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
711
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
712
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
713
		#必填寫的參數:
714
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
715
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
716
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
717
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("username","password","receiverMail","subject","plainBody","htmlBody","fileArgu");
226 liveuser 718
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
3 liveuser 719
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","array","string","string","string","string");
720
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
721
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
722
		#可以省略的參數:
723
		#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
724
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
725
		#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
726
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("attachment","attachmentName","attachmentMimeType","mailServer","mailerMailDisplay","mailerNameDisplay","receiverMailDisplay","receiverNameDisplay","levelForCheckSSL");
226 liveuser 727
		#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 728
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array","array","array","string","string","string","string","string","string");
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");
731
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
732
		$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("receiverMail","receiverMailDisplay","receiverNameDisplay");
733
		#參考資料來源:
734
		#array_keys=>http://php.net/manual/en/function.array-keys.php
735
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
736
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 737
 
3 liveuser 738
		#如果檢查失敗
739
		if($checkArguments["status"]=="false"){
226 liveuser 740
 
3 liveuser 741
			#設置錯誤識別
742
			$result["status"]="false";
226 liveuser 743
 
3 liveuser 744
			#設置錯誤訊息
745
			$result["error"]=$checkArguments;
226 liveuser 746
 
3 liveuser 747
			#回傳結果
748
			return $result;
226 liveuser 749
 
3 liveuser 750
			}#if end
226 liveuser 751
 
3 liveuser 752
		#如果檢查不通過
753
		if($checkArguments["passed"]=="false"){
226 liveuser 754
 
3 liveuser 755
			#設置錯誤識別
756
			$result["status"]="false";
226 liveuser 757
 
3 liveuser 758
			#設置錯誤訊息
759
			$result["error"]=$checkArguments;
226 liveuser 760
 
3 liveuser 761
			#回傳結果
762
			return $result;
226 liveuser 763
 
3 liveuser 764
			}#if end
226 liveuser 765
 
3 liveuser 766
		#檢查 curlSmtp 資料夾是否存在
767
		#函式說明:檢查多個檔案是否存在
768
		#回傳的結果:
769
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
770
		#$result["error"],錯誤訊息陣列.
771
		#$resutl["function"],當前執行的涵式名稱.
772
		#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
773
		#$result["varName"][$i],爲第$i個資料夾或檔案的名稱。
774
		#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
775
		#必填參數:
776
		$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array(".curlSmtp");#要檢查書否存在的檔案有哪些,須爲一維陣列數值。
777
		$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
778
		#參考資料來源:
779
		#http://php.net/manual/en/function.file-exists.php
780
		#http://php.net/manual/en/control-structures.foreach.php
781
		$checkMutiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
782
		unset($conf["fileAccess::checkMultiFileExist"]);
226 liveuser 783
 
3 liveuser 784
		#如果檢查檔案失敗
785
		if($checkMutiFileExist["status"]=="false"){
226 liveuser 786
 
3 liveuser 787
			#設置錯誤識別
788
			$result["status"]="false";
226 liveuser 789
 
3 liveuser 790
			#設置錯誤訊息
791
			$result["error"]=$checkMutiFileExist;
226 liveuser 792
 
3 liveuser 793
			#回傳結果
794
			return $result;
226 liveuser 795
 
3 liveuser 796
			}#if end
797
 
798
		#如果該資料夾不存在
799
		if($checkMutiFileExist["varExist"][0]=="false"){
800
 
801
			#則建立該資料夾
802
			#函式說明:
803
			#建立資料夾,若要建立的資料夾所屬路徑不存在,則會自動嘗試建立,建立後的資料夾也可指定權限.
804
			#回傳結果:
805
			#$result["status"],"true"爲建立成功,"false"爲建立失敗.
806
			#$result["error"],錯誤訊息陣列
807
			#必填參數:
808
			$conf["fileAccess::createFolderAfterCheck"]["dirPositionAndName"]=".curlSmtp";#新建的位置與名稱
809
			$conf["fileAccess::createFolderAfterCheck"]["fileArgu"]=$conf["fileArgu"];
810
			#可省略參數:
811
			#$conf["fileAccess::createFolderAfterCheck"]["dirPermission"]="";#新建資料夾的權限設定,預設爲0770,亦即擁有者,同群組者可以讀,寫,存取,其他人僅能存取.
812
			$createFolderAfterCheck=fileAccess::createFolderAfterCheck($conf["fileAccess::createFolderAfterCheck"]);
813
			unset($conf["fileAccess::createFolderAfterCheck"]);
226 liveuser 814
 
3 liveuser 815
			#如果 建立資料夾失敗
816
			if($createFolderAfterCheck["status"]=="false"){
817
 
818
				#設置錯誤識別
819
				$result["status"]="false";
820
 
821
				#設置錯誤訊息
822
				$result["errot"]=$createFolderAfterCheck;
823
 
824
				#回傳結果
825
				return $result;
826
 
827
				}#if end
828
 
829
			}#if end
226 liveuser 830
 
48 liveuser 831
		#取得 $systemTime
3 liveuser 832
		$systemTime=time::getMicrotime();
833
 
834
		#要傳送的信件資訊
835
		$mailFileHeader="From: ".$conf["mailerNameDisplay"]." <".$conf["mailerMailDisplay"].">\r\n";
226 liveuser 836
 
3 liveuser 837
		#第一個人主要收件人
226 liveuser 838
		$mailFileHeader=$mailFileHeader."To: ".$conf["receiverNameDisplay"][0]." "."<".$conf["receiverMailDisplay"][0].">\r\n";
839
 
3 liveuser 840
		#如果有其餘收件人
841
		if(count($conf["receiverNameDisplay"])>1){
226 liveuser 842
 
3 liveuser 843
			#副本寄送處的資訊開始
844
			$mailFileHeader=$mailFileHeader."Cc: ";
226 liveuser 845
 
3 liveuser 846
			}#if end
226 liveuser 847
 
3 liveuser 848
		#針對其餘收件人的地址
849
		for($i=1;$i<count($conf["receiverNameDisplay"]);$i++){
226 liveuser 850
 
3 liveuser 851
			#如果不是最後一筆
852
			if($i!=count($conf["receiverNameDisplay"])-1){
226 liveuser 853
 
3 liveuser 854
				$mailFileHeader=$mailFileHeader.$conf["receiverNameDisplay"][$i]." <".$conf["receiverMailDisplay"][$i].">,";
226 liveuser 855
 
3 liveuser 856
				}#if end
226 liveuser 857
 
3 liveuser 858
			#反之是最後一筆
859
			else{
226 liveuser 860
 
3 liveuser 861
				$mailFileHeader=$mailFileHeader.$conf["receiverNameDisplay"][$i]." <".$conf["receiverMailDisplay"][$i].">\r\n";
226 liveuser 862
 
863
				}#else end
864
 
3 liveuser 865
			}#for end
226 liveuser 866
 
3 liveuser 867
		$mailFileHeader=$mailFileHeader."Subject: ".$conf["subject"]."\r\n";
226 liveuser 868
 
3 liveuser 869
		#初始化信件本文
870
		$mailFileContent="";
226 liveuser 871
 
3 liveuser 872
		#初始化 boundary
873
		$boundary="001a11c30ce8aec3480533bfa9a9";
226 liveuser 874
 
3 liveuser 875
		#初始化 boundary start
876
		$boundaryS="--".$boundary;
226 liveuser 877
 
878
		#初始化 boundary end
3 liveuser 879
		$boundaryE=$boundaryS."--";
226 liveuser 880
 
881
		#設置信件本文(純文字與html兩種)
3 liveuser 882
		$mailFileContent=$mailFileContent."Content-Type: multipart/alternative; boundary=\"".$boundary."\"\r\n";
883
		$mailFileContent=$mailFileContent."\r\n";
884
		$mailFileContent=$mailFileContent.$boundaryS."\r\n";
885
		$mailFileContent=$mailFileContent."Content-Type: text/plain; charset=UTF-8\r\n";
886
		$mailFileContent=$mailFileContent."\r\n";
887
		$mailFileContent=$mailFileContent.$conf["plainBody"]."\r\n";
888
		$mailFileContent=$mailFileContent."\r\n";
889
		$mailFileContent=$mailFileContent.$boundaryS."\r\n";
890
		$mailFileContent=$mailFileContent."Content-Type: text/html; charset=UTF-8\r\n";
891
		$mailFileContent=$mailFileContent."\r\n";
892
		$mailFileContent=$mailFileContent.$conf["htmlBody"]."\r\n";
226 liveuser 893
		$mailFileContent=$mailFileContent.$boundaryE."\r\n";
894
 
3 liveuser 895
		#依據規定,每列不得大於70的字元
896
		$mailFileContent==wordwrap($mailFileContent,70,"\r\n",true);
226 liveuser 897
 
3 liveuser 898
		#如果有設定要上傳附件
899
		if(isset($conf["attachment"])){
226 liveuser 900
 
3 liveuser 901
			#依據每個附件
902
			for($i=0;$i<count($conf["attachment"]);$i++){
226 liveuser 903
 
3 liveuser 904
				#初始化寄送附件的語法
905
				$attachment="";
226 liveuser 906
 
3 liveuser 907
				#確認目標檔案是否存在
908
				#函式說明:檢查多個檔案是否存在
909
				#回傳的結果:
910
				#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
911
				#$result["error"],錯誤訊息陣列.
912
				#$resutl["function"],當前執行的涵式名稱.
913
				#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
914
				#$result["varName"][$i],爲第$i個資料夾或檔案的名稱。
915
				#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
916
				#必填參數:
917
				$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
918
				$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($conf["attachment"][$i]);#要檢查書否存在的檔案有哪些,須爲一維陣列數值。
919
				#參考資料來源:
920
				#http://php.net/manual/en/function.file-exists.php
921
				#http://php.net/manual/en/control-structures.foreach.php
922
				$checkMutiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
923
				unset($conf["fileAccess::checkMultiFileExist"]);
226 liveuser 924
 
3 liveuser 925
				#如果檢查失敗
926
				if($checkMutiFileExist["status"]=="false"){
226 liveuser 927
 
3 liveuser 928
					#設置錯誤識別
929
					$result["status"]="false";
930
 
931
					#設置錯誤資訊
932
					$result["error"]=$checkMutiFileExist;
933
 
934
					#回傳結果
935
					return $result;
226 liveuser 936
 
3 liveuser 937
					}#if end
226 liveuser 938
 
3 liveuser 939
				#如果檔案不存在
940
				if($checkMutiFileExist["varExist"][0]=="false"){
226 liveuser 941
 
3 liveuser 942
					#設置錯誤識別
943
					$result["status"]="false";
944
 
945
					#設置錯誤資訊
946
					$result["error"]=$checkMutiFileExist;
947
 
948
					#回傳結果
949
					return $result;
226 liveuser 950
 
3 liveuser 951
					}#if end
226 liveuser 952
 
3 liveuser 953
				#如果是第一個附件
954
				if($i==0){
226 liveuser 955
 
3 liveuser 956
					#在前面加上 multipart/mixed 的 boundary
957
					$mailFileContent="Content-Type: multipart/mixed; boundary=".$boundary."\r\n\r\n".$mailFileContent;
226 liveuser 958
 
3 liveuser 959
					}#if end
226 liveuser 960
 
3 liveuser 961
				#如果 $conf["attachmentName"] 不存在
962
				if(!isset($conf["attachmentName"])){
226 liveuser 963
 
3 liveuser 964
					#涵是說明:
965
					#取得檔案路徑字串的路徑與檔案的名稱與檔案副檔名
966
					#回傳的結果:
967
					#$result["status"],執行是否正常,"true"正常,"false"代表不正常.
968
					#$result["error"],錯誤訊息.
969
					#$result["function"],當前執行的函式名稱.
970
					#$result["filePath"],路徑字串.
971
					#$result["fileName"],檔案名稱字串.
972
					#$result["fileExtention"],檔案的副檔名.
973
					#$result["fullFileName"],含副檔名的檔案名稱.
974
					#$result["fullFilePathAndName"],完整的檔案路徑(含副檔名).
975
					#必填參數:
976
					#$conf["fileAddressAndName"],字串,檔案名稱與其路徑.
977
					$conf["fileAccess::getFileAddressAndNameAndFileExtention"]["fileAddressAndName"]=$conf["attachment"][$i];
978
					#可省略的參數:
979
					#無.
980
					$getFileAddressAndNameAndFileExtention=fileAccess::getFileAddressAndNameAndFileExtention($conf["fileAccess::getFileAddressAndNameAndFileExtention"]);
981
					unset($conf["fileAccess::getFileAddressAndNameAndFileExtention"]);
226 liveuser 982
 
983
					#如果解析檔案資訊失敗
3 liveuser 984
					if($getFileAddressAndNameAndFileExtention["status"]=="false"){
226 liveuser 985
 
3 liveuser 986
						#設置錯誤識別
987
						$result["status"]="false";
988
 
989
						#設置錯誤資訊
990
						$result["error"]=$getFileAddressAndNameAndFileExtention;
991
 
992
						#回傳結果
993
						return $result;
226 liveuser 994
 
995
						}#if end
996
 
3 liveuser 997
					#設定附件名稱
998
					$conf["attachmentName"][$i]=$getFileAddressAndNameAndFileExtention["fullFileName"];
226 liveuser 999
 
3 liveuser 1000
					}#if end
226 liveuser 1001
 
3 liveuser 1002
				#反之如果 $conf["attachmentName"][$i] 不存在
1003
				else if(!isset($conf["attachmentName"][$i])){
226 liveuser 1004
 
3 liveuser 1005
					#涵是說明:
1006
					#取得檔案路徑字串的路徑與檔案的名稱與檔案副檔名
1007
					#回傳的結果:
1008
					#$result["status"],執行是否正常,"true"正常,"false"代表不正常.
1009
					#$result["error"],錯誤訊息.
1010
					#$result["function"],當前執行的函式名稱.
1011
					#$result["filePath"],路徑字串.
1012
					#$result["fileName"],檔案名稱字串.
1013
					#$result["fileExtention"],檔案的副檔名.
1014
					#$result["fullFileName"],含副檔名的檔案名稱.
1015
					#$result["fullFilePathAndName"],完整的檔案路徑(含副檔名).
1016
					#必填參數:
1017
					#$conf["fileAddressAndName"],字串,檔案名稱與其路徑.
1018
					$conf["fileAccess::getFileAddressAndNameAndFileExtention"]["fileAddressAndName"]=$conf["attachment"][$i];
1019
					#可省略的參數:
1020
					#無.
1021
					$getFileAddressAndNameAndFileExtention=fileAccess::getFileAddressAndNameAndFileExtention($conf["fileAccess::getFileAddressAndNameAndFileExtention"]);
1022
					unset($conf["fileAccess::getFileAddressAndNameAndFileExtention"]);
226 liveuser 1023
 
1024
					#如果解析檔案資訊失敗
3 liveuser 1025
					if($getFileAddressAndNameAndFileExtention["status"]=="false"){
226 liveuser 1026
 
3 liveuser 1027
						#設置錯誤識別
1028
						$result["status"]="false";
1029
 
1030
						#設置錯誤資訊
1031
						$result["error"]=$getFileAddressAndNameAndFileExtention;
1032
 
1033
						#回傳結果
1034
						return $result;
226 liveuser 1035
 
1036
						}#if end
1037
 
3 liveuser 1038
					#設定附件名稱
1039
					$conf["attachmentName"][$i]=$getFileAddressAndNameAndFileExtention["fullFileName"];
226 liveuser 1040
 
3 liveuser 1041
					}#if end
226 liveuser 1042
 
3 liveuser 1043
				#如果 $conf["attachmentMimeType"] 不存在
1044
				if(!isset($conf["attachmentMimeType"])){
226 liveuser 1045
 
3 liveuser 1046
					#設定檔案類型
1047
					$conf["attachmentMimeType"][$i]="application/*";
226 liveuser 1048
 
1049
					}#if end
1050
 
1051
				#反之如果 $conf["attachmentMimeType"][$i] 不存在
3 liveuser 1052
				if(!isset($conf["attachmentMimeType"][$i])){
226 liveuser 1053
 
3 liveuser 1054
					$conf["attachmentMimeType"][$i]="application/*";
226 liveuser 1055
 
3 liveuser 1056
					}#if end
226 liveuser 1057
 
3 liveuser 1058
				#加上寄送附件的語法
1059
				$attachment=$attachment.$boundaryS."\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";
226 liveuser 1062
				$attachment=$attachment."Content-Transfer-Encoding: base64\r\n";
3 liveuser 1063
				$attachment=$attachment."X-Attachment-Id: f_io1ikfii".$i."\r\n";
226 liveuser 1064
 
1065
				#將檔案用base64加密
3 liveuser 1066
				$base64fileStr=base64_encode(file_get_contents($conf["attachment"][$i]));
226 liveuser 1067
 
3 liveuser 1068
				#依據規定,每列不得大於70的字元
1069
				$wordwrapedFileStr=wordwrap($base64fileStr,70,"\r\n",true);
226 liveuser 1070
 
3 liveuser 1071
				#斷行後附加檔案字串
226 liveuser 1072
				$attachment=$attachment."\r\n".$wordwrapedFileStr."\r\n";
1073
 
3 liveuser 1074
				#如果是最後一個附件
1075
				if($i==count($conf["attachment"])-1){
226 liveuser 1076
 
3 liveuser 1077
					#混合資料結尾
1078
					$attachment=$attachment.$boundary."\r\n";
226 liveuser 1079
 
1080
					}#if end
1081
 
3 liveuser 1082
				#增加到信件內文的結尾
1083
				$mailFileContent=$mailFileContent.$attachment;
226 liveuser 1084
 
3 liveuser 1085
				}#for end
226 liveuser 1086
 
3 liveuser 1087
			}#if end
226 liveuser 1088
 
3 liveuser 1089
		#建立要寄送的郵件檔案
1090
		#函式說明:
226 liveuser 1091
		#建立暫存目錄與回傳暫存檔案名稱路徑
3 liveuser 1092
		#回傳結果:
1093
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1094
		#$result["error"],錯誤訊息.
1095
		#$result["function"],當前執行的函數名稱.
1096
		#$result["content"],暫存檔案的路徑與名稱.
1097
		#必填參數:
1098
		#無.
1099
		#可省略參數:
1100
		#無.
1101
		#參考資料:
1102
		#無.
1103
		#備註:
1104
		#無.
35 liveuser 1105
		$conf["conffileAccess::createTempFile"]=array();
1106
		$createTempFile=fileAccess::createTempFile($conf["conffileAccess::createTempFile"]);
1107
		unset($conf["conffileAccess::createTempFile"]);
226 liveuser 1108
 
3 liveuser 1109
		#如果檔案建立失敗
1110
		if($createTempFile["status"]=="false"){
1111
 
1112
			#設置錯誤識別
1113
			$result["status"]="false";
1114
 
1115
			#設置錯誤資訊
1116
			$result["error"]=$createTempFile;
1117
 
1118
			#回傳結果
1119
			return $result;
1120
 
1121
			}#if end
226 liveuser 1122
 
3 liveuser 1123
		#取得要寄送的郵件檔案
1124
		$mailFile=$createTempFile["content"];
226 liveuser 1125
 
3 liveuser 1126
		#將字串寫入到檔案
1127
		#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
1128
		#$result["error"],錯誤訊息陣列.
1129
		#必填參數:
1130
		$conf["fileAccess::writeTextIntoFile"]["fileName"]=$mailFile;#爲要編輯的檔案名稱
1131
		$conf["fileAccess::writeTextIntoFile"]["inputString"]=$mailFileHeader.$mailFileContent;#爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可。
1132
		$conf["fileAccess::writeTextIntoFile"]["fileArgu"]=$conf["fileArgu"];
1133
		#可省略參數:
1134
		#$conf["writeMethod"]="a";#爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入。
1135
		#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
1136
		$conf["fileAccess::writeTextIntoFile"]["web"]="false";
1137
		$writeTextIntoFile=fileAccess::writeTextIntoFile($conf["fileAccess::writeTextIntoFile"]);
1138
		unset($conf["fileAccess::writeTextIntoFile"]);
1139
 
1140
		#如果檔案建立失敗
1141
		if($writeTextIntoFile["status"]=="false"){
1142
 
1143
			#設置錯誤識別
1144
			$result["status"]="false";
1145
 
1146
			#設置錯誤資訊
1147
			$result["error"]=$writeTextIntoFile;
1148
 
1149
			#回傳結果
1150
			return $result;
1151
 
1152
			}#if end
1153
 
1154
		#要執行的系統命令
1155
		$paramArray=array();
226 liveuser 1156
 
3 liveuser 1157
		#設置要用 ssl
1158
		$paramArray[]="--ssl-reqd";
1159
 
1160
		#如果為 "levelForCheckSSL" 為 "none"
1161
		if($conf["levelForCheckSSL"]==="none"){
226 liveuser 1162
 
3 liveuser 1163
			#設置不用確認ssl符合規範
1164
			$paramArray[]="-k";
226 liveuser 1165
 
3 liveuser 1166
			}#if end
1167
 
1168
		#設置要設定url
1169
		$paramArray[]="--url";
226 liveuser 1170
 
3 liveuser 1171
		#設置smtp server
1172
		$paramArray[]=$conf["mailServer"];
226 liveuser 1173
 
3 liveuser 1174
		#設置指定使用者名稱
1175
		$paramArray[]="-u";
226 liveuser 1176
 
3 liveuser 1177
		#設置使用名稱與密碼
1178
		$paramArray[]=$conf["username"].":".$conf["password"];
226 liveuser 1179
 
3 liveuser 1180
		#設置要指定寄信來源顯示的名稱
1181
		$paramArray[]="--mail-from";
226 liveuser 1182
 
3 liveuser 1183
		#設置寄信來源顯示的名稱
1184
		$paramArray[]=$conf["mailerMailDisplay"];
226 liveuser 1185
 
3 liveuser 1186
		#有幾個收件人就執行幾次
1187
		foreach($conf["receiverMail"] as $mailTo){
226 liveuser 1188
 
3 liveuser 1189
			#指定收件人的參數
1190
			$paramArray[]="--mail-rcpt";
226 liveuser 1191
 
3 liveuser 1192
			#串接收件人
1193
			$paramArray[]=$mailTo;
226 liveuser 1194
 
3 liveuser 1195
			}#for end
226 liveuser 1196
 
3 liveuser 1197
		#指定mail檔案
1198
		$paramArray[]="--upload-file";
1199
		$paramArray[]=$mailFile;
226 liveuser 1200
 
3 liveuser 1201
		#看過程
1202
		$paramArray[]="-v";
226 liveuser 1203
 
3 liveuser 1204
		#用curl寄送信件
1205
		#函式說明:
1206
		#呼叫shell執行系統命令,並取得回傳的內容.
1207
		#回傳的結果:
1208
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1209
		#$result["error"],錯誤訊息陣列.
1210
		#$result["function"],當前執行的函數名稱.
1211
		#$result["cmd"],執行的指令內容.
1212
		#$result["output"],爲執行完二元碼後的輸出陣列.
1213
		#必填參數:
1214
		$conf["external::callShell"]["command"]="curl";#要執行的指令與參
1215
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
1216
		#可省略參數:
1217
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
1218
		$conf["external::callShell"]["argu"]=$paramArray;
1219
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
1220
		#$conf["enablePrintDescription"]="true";
1221
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
1222
		#$conf["printDescription"]="";
1223
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
1224
		$conf["external::callShell"]["escapeshellarg"]="true";
1225
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行apache的使用者,該參數不適用於apache環境.
1226
		#$conf["username"]="";
1227
		#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
1228
		#$conf["password"]="";
1229
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要;"false"代表不要,預設為"false".
1230
		#$conf["useScript"]="";
1231
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 ".qbpwcf_tmp/external/callShell/".
1232
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
1233
		#$conf["fileArgu"],字串,變數__FILE__的內容,預設為當前檔案的路徑與名稱.
226 liveuser 1234
		#$conf["fileArgu"]="";
3 liveuser 1235
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false".
1236
		#$conf["external::callShell"]["inBackGround"]="true";
1237
		#參考資料:
1238
		#http://php.net/manual/en/function.exec.php
1239
		$external["callShell"]=external::callShell($conf["external::callShell"]);
1240
		unset($conf["external::callShell"]);
1241
 
1242
		#如果 $external["callShell"] 等於 "false"
1243
		if($external["callShell"]["status"]==="false"){
226 liveuser 1244
 
3 liveuser 1245
			#如果 "levelForCheckSSL" 為 "loose"
1246
			if($conf["levelForCheckSSL"]==="loose"){
226 liveuser 1247
 
3 liveuser 1248
				#加上 "-k" 參數,這次不用符合ssl規範
1249
				$paramArray[]="-k";
226 liveuser 1250
 
3 liveuser 1251
				#用curl寄送信件
1252
				#函式說明:
1253
				#呼叫shell執行系統命令,並取得回傳的內容.
1254
				#回傳的結果:
1255
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1256
				#$result["error"],錯誤訊息陣列.
1257
				#$result["function"],當前執行的函數名稱.
1258
				#$result["cmd"],執行的指令內容.
1259
				#$result["output"],爲執行完二元碼後的輸出陣列.
1260
				#必填參數:
1261
				$conf["external::callShell"]["command"]="curl";#要執行的指令與參
1262
				$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
1263
				#可省略參數:
1264
				#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
1265
				$conf["external::callShell"]["argu"]=$paramArray;
1266
				#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
1267
				#$conf["enablePrintDescription"]="true";
1268
				#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
1269
				#$conf["printDescription"]="";
1270
				#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
1271
				$conf["external::callShell"]["escapeshellarg"]="true";
1272
				#$conf["username"],字串,要用什麼使用者來執行,預設為執行apache的使用者,該參數不適用於apache環境.
1273
				#$conf["username"]="";
1274
				#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
1275
				#$conf["password"]="";
1276
				#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要;"false"代表不要,預設為"false".
1277
				#$conf["useScript"]="";
1278
				#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 ".qbpwcf_tmp/external/callShell/".
1279
				#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
1280
				#$conf["fileArgu"],字串,變數__FILE__的內容,預設為當前檔案的路徑與名稱.
226 liveuser 1281
				#$conf["fileArgu"]="";
3 liveuser 1282
				#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false".
1283
				#$conf["external::callShell"]["inBackGround"]="true";
1284
				#參考資料:
1285
				#http://php.net/manual/en/function.exec.php
1286
				$external["callShell"]=external::callShell($conf["external::callShell"]);
1287
				unset($conf["external::callShell"]);
226 liveuser 1288
 
3 liveuser 1289
				#如果 $external["callShell"] 等於 "false"
1290
				if($external["callShell"]["status"]==="false"){
226 liveuser 1291
 
3 liveuser 1292
					#設置錯誤識別
1293
					$result["status"]="false";
226 liveuser 1294
 
3 liveuser 1295
					#設置錯誤訊息
1296
					$result["error"]=$external["callShell"];
226 liveuser 1297
 
3 liveuser 1298
					#回傳結果
1299
					return $result;
226 liveuser 1300
 
3 liveuser 1301
					}#if end
226 liveuser 1302
 
3 liveuser 1303
				}#if end
226 liveuser 1304
 
3 liveuser 1305
			#反之
1306
			else{
226 liveuser 1307
 
3 liveuser 1308
				#設置錯誤識別
1309
				$result["status"]="false";
226 liveuser 1310
 
3 liveuser 1311
				#設置錯誤訊息
1312
				$result["error"]=$external["callShell"];
226 liveuser 1313
 
3 liveuser 1314
				#回傳結果
1315
				return $result;
226 liveuser 1316
 
3 liveuser 1317
				}#else end`
226 liveuser 1318
 
3 liveuser 1319
			}#if end
226 liveuser 1320
 
3 liveuser 1321
		#取得較完整的指令
1322
		$result["cmd"]=$external["callShell"]["cmd"];
226 liveuser 1323
 
3 liveuser 1324
		#移除信件檔案
1325
		#函式說明:
1326
		#移除檔案
1327
		#回傳結果:
1328
		#$result["status"],"true"代表移除成功,"false"代表移除失敗.
1329
		#$result["error"],錯誤訊息陣列
1330
		#$result["warning"],警告訊息陣列
1331
		#$result["function"],當前執行的函數名稱
1332
		#必填參數:
1333
		$conf["fileAccess::delFile"]["fileAddress"]=$mailFile;#要移除檔案的位置
1334
		$conf["fileAccess::delFile"]["fileArgu"]=$conf["fileArgu"];
1335
		$delMailFile=fileAccess::delFile($conf["fileAccess::delFile"]);
1336
		unset($conf["fileAccess::delFile"]);
1337
 
1338
		#如果移除信件檔案失敗
1339
		if($delMailFile["status"]==="false"){
1340
 
1341
			#設置錯誤識別
1342
			$result["status"]="false";
226 liveuser 1343
 
3 liveuser 1344
			#設置錯誤訊息
1345
			$result["error"]=$delMailFile;
226 liveuser 1346
 
3 liveuser 1347
			#回傳結果
1348
			return $result;
1349
 
1350
			}#if end
1351
 
1352
		#可以執行到這邊,就表示十之八九寄信成功了
1353
		$result["status"]="true";
226 liveuser 1354
 
3 liveuser 1355
		#回傳結果
1356
		return $result;
1357
 
1358
		}#function curlSmtp end
226 liveuser 1359
 
3 liveuser 1360
	/*
1361
	#函式說明:
1362
	#使用 linux 的 curl 指令來透過SMTP伺服器寄大量不同內容的信件.
1363
	#回傳結果:
1364
	#$result["status"],寄信的情況,若爲"true",則十之八九沒有問題.
1365
	#$result["error"],錯誤訊息陣列
1366
	#$result["function"],當前執行的函數
1367
	#$result["warning"],警示訊息,一些不會導致失敗但不能說是完美的問題.
1368
	#$result["cmd"],寄信的指令.
1369
	#$result["detailCmd"],較詳細的寄信指令.
1370
	#必填參數:
1371
	#$conf["username"],字串,用來登入郵件伺服器的帳號
1372
	$conf["username"]="";
1373
	#$conf["password"],字串,用來登入郵件伺服器的密碼
1374
	$conf["password"]="";
1375
	#$conf["receiverMail"],二維字串陣列,每個信件的收件人信箱有哪些.
1376
	$conf["receiverMail"]=array(array());
1377
	#$conf["subject"],字串陣列,每封郵件的主題.
1378
	$conf["subject"]=array("");
1379
	#$conf["plainBody"],字串陣列,郵件本文的純文字內容.
1380
	$conf["plainBody"]=array("");
1381
	#$conf["htmlBody"]="";,字串陣列,郵件本文的html內容,多媒體盡量不要用base64的方式來嵌入,因為大部分的郵件服務(Gmail)都不支援,如果是在單機上的郵件軟體就可能有支援,例如:Evolution.
1382
	$conf["htmlBody"]=array("");
1383
	#$conf["fileArgu"],字串,php內建變數「__FILE__」的內容.
1384
	$conf["fileArgu"]=__FILE__;
1385
	#可省略參數:
1386
	#$conf["usernameOnly"],字串,登入的帳號是否只要名稱不要@,預設爲"false"使用完整名稱跟@;反之爲"false".
1387
	#$conf["usernameOnly"]="false";
1388
	#$conf["mailServer"],字串,要使用的SMTP郵件伺服器網址與連接口,預設爲 smtps://smtp.gmail.com:465
1389
	#$conf["mailServer"]="";
1390
	#$conf["mailerMailDisplay"],字串,要顯示的寄件人信箱,預設爲 $conf["username"]
1391
	#$conf["mailerMailDisplay"]="";
1392
	#$conf["mailerNameDisplay"],字串,要顯示的寄件人姓名,預設爲 $conf["username"]
1393
	#$conf["mailerNameDisplay"]="";
1394
	#$conf["receiverMailDisplay"],陣列,每封信要顯示的收件人信箱,預設爲 $conf["receiverMail"] 對應的元素.
1395
	#$conf["receiverMailDisplay"]=array("");
1396
	#$conf["receiverNameDisplay"],陣列,每封信要顯示的收件人姓名,預設爲 $conf["receiverMail"] 對應的元素.
1397
	#$conf["receiverNameDisplay"]=array("");
1398
	#$conf["attachment"],二維陣列,每個信件要寄送的附件路徑與檔案名稱
1399
	#$conf["attachment"]=array(array());
1400
	#$conf["attachmentName"],二維陣列,每個信件要寄送的附件顯示名稱,預設為$conf["attachment"]中的實際檔案名稱.
1401
	#$conf["attachmentName"]=array(array());
1402
	#$conf["attachmentMimeType"],二維陣列,每個信件附件的 mimeType,預設為"application/*".
1403
	#$conf["attachmentMimeType"]array(array());
1404
	#$conf["insecure"],字串,是否允許不安全的tls連線,預設爲"false"不允許,"true"爲允許.
1405
	#$conf["insecure"]="false";
1406
	#參考資料:
1407
	#無.
1408
	#備註:
1409
	#無.
1410
	*/
1411
	public static function multiCurlSmtp(&$conf){
226 liveuser 1412
 
3 liveuser 1413
		#初始化要回傳的結果
1414
		$result=array();
1415
 
1416
		#儲存當前執行的函數
1417
		$result["function"]=__FUNCTION__;
1418
 
1419
		#如果 $conf 不為陣列
1420
		if(gettype($conf)!="array"){
226 liveuser 1421
 
3 liveuser 1422
			#設置執行失敗
1423
			$result["status"]="false";
226 liveuser 1424
 
3 liveuser 1425
			#設置執行錯誤訊息
1426
			$result["error"][]="\$conf變數須為陣列形態";
1427
 
1428
			#如果傳入的參數為 null
1429
			if($conf==null){
226 liveuser 1430
 
3 liveuser 1431
				#設置執行錯誤訊息
1432
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 1433
 
3 liveuser 1434
				}#if end
1435
 
1436
			#回傳結果
1437
			return $result;
226 liveuser 1438
 
3 liveuser 1439
			}#if end
226 liveuser 1440
 
3 liveuser 1441
		#檢查參數
1442
		#函式說明:
1443
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
1444
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1445
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
1446
		#$result["function"],當前執行的函式名稱.
1447
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
1448
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
1449
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
1450
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
1451
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
1452
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
1453
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
1454
		#必填寫的參數:
1455
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
1456
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
1457
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
1458
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("username","password","receiverMail","subject","plainBody","htmlBody","fileArgu");
226 liveuser 1459
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
3 liveuser 1460
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","array","array","array","array","string");
1461
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
1462
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
1463
		#可以省略的參數:
1464
		#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
1465
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
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");
226 liveuser 1468
		#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 1469
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array","array","array","string","string","string","array","array","string","string");
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");
1472
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
1473
		$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("subject","plainBody","htmlBody","receiverMail","receiverMailDisplay","receiverNameDisplay");
1474
		#參考資料來源:
1475
		#array_keys=>http://php.net/manual/en/function.array-keys.php
1476
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
1477
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 1478
 
3 liveuser 1479
		#如果檢查失敗
1480
		if($checkArguments["status"]=="false"){
226 liveuser 1481
 
3 liveuser 1482
			#設置錯誤識別
1483
			$result["status"]="false";
226 liveuser 1484
 
3 liveuser 1485
			#設置錯誤訊息
1486
			$result["error"]=$checkArguments;
226 liveuser 1487
 
3 liveuser 1488
			#回傳結果
1489
			return $result;
226 liveuser 1490
 
3 liveuser 1491
			}#if end
226 liveuser 1492
 
3 liveuser 1493
		#如果檢查不通過
1494
		if($checkArguments["passed"]=="false"){
226 liveuser 1495
 
3 liveuser 1496
			#設置錯誤識別
1497
			$result["status"]="false";
226 liveuser 1498
 
3 liveuser 1499
			#設置錯誤訊息
1500
			$result["error"]=$checkArguments;
226 liveuser 1501
 
3 liveuser 1502
			#回傳結果
1503
			return $result;
226 liveuser 1504
 
3 liveuser 1505
			}#if end
226 liveuser 1506
 
3 liveuser 1507
		#檢查 .curlSmtp 資料夾是否存在
1508
		#函式說明:檢查多個檔案是否存在
1509
		#回傳的結果:
1510
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
1511
		#$result["error"],錯誤訊息陣列.
1512
		#$resutl["function"],當前執行的涵式名稱.
1513
		#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
1514
		#$result["varName"][$i],爲第$i個資料夾或檔案的名稱。
1515
		#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
1516
		#必填參數:
1517
		$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array(".curlSmtp");#要檢查書否存在的檔案有哪些,須爲一維陣列數值。
1518
		$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
1519
		#參考資料來源:
1520
		#http://php.net/manual/en/function.file-exists.php
1521
		#http://php.net/manual/en/control-structures.foreach.php
1522
		$checkMutiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
1523
		unset($conf["fileAccess::checkMultiFileExist"]);
226 liveuser 1524
 
3 liveuser 1525
		#如果檢查檔案失敗
1526
		if($checkMutiFileExist["status"]=="false"){
226 liveuser 1527
 
3 liveuser 1528
			#設置錯誤識別
1529
			$result["status"]="false";
226 liveuser 1530
 
3 liveuser 1531
			#設置錯誤訊息
1532
			$result["error"]=$checkMutiFileExist;
226 liveuser 1533
 
3 liveuser 1534
			#回傳結果
1535
			return $result;
226 liveuser 1536
 
3 liveuser 1537
			}#if end
1538
 
1539
		#如果該資料夾不存在
1540
		if($checkMutiFileExist["varExist"][0]=="false"){
1541
 
1542
			#則建立該資料夾
1543
			#函式說明:
1544
			#建立資料夾,若要建立的資料夾所屬路徑不存在,則會自動嘗試建立,建立後的資料夾也可指定權限.
1545
			#回傳結果:
1546
			#$result["status"],"true"爲建立成功,"false"爲建立失敗.
1547
			#$result["error"],錯誤訊息陣列
1548
			#必填參數:
1549
			$conf["fileAccess::createFolderAfterCheck"]["dirPositionAndName"]=".curlSmtp";#新建的位置與名稱
1550
			$conf["fileAccess::createFolderAfterCheck"]["fileArgu"]=$conf["fileArgu"];
1551
			#可省略參數:
1552
			#$conf["fileAccess::createFolderAfterCheck"]["dirPermission"]="";#新建資料夾的權限設定,預設爲0770,亦即擁有者,同群組者可以讀,寫,存取,其他人僅能存取.
1553
			$createFolderAfterCheck=fileAccess::createFolderAfterCheck($conf["fileAccess::createFolderAfterCheck"]);
1554
			unset($conf["fileAccess::createFolderAfterCheck"]);
226 liveuser 1555
 
3 liveuser 1556
			#如果 建立資料夾失敗
1557
			if($createFolderAfterCheck["status"]=="false"){
1558
 
1559
				#設置錯誤識別
1560
				$result["status"]="false";
1561
 
1562
				#設置錯誤訊息
1563
				$result["errot"]=$createFolderAfterCheck;
1564
 
1565
				#回傳結果
1566
				return $result;
1567
 
1568
				}#if end
1569
 
1570
			}#if end
226 liveuser 1571
 
3 liveuser 1572
		#初始化寄信的command
1573
		#$mailCmd="";
226 liveuser 1574
 
3 liveuser 1575
		#初始化寄信的指令
226 liveuser 1576
		$mailCmdArray=array();
1577
 
3 liveuser 1578
		#初始化移除信件檔案的指令
1579
		$delMailFileCmd=array();
226 liveuser 1580
 
1581
		#取得 $systemTime
3 liveuser 1582
		$systemTime=time::getMicrotime();
1583
 
1584
		#要傳送的信件資訊
1585
		$fromInfo="From: ".$conf["mailerNameDisplay"]." <".$conf["mailerMailDisplay"].">\r\n";
226 liveuser 1586
 
3 liveuser 1587
		#初始化信件的 header
1588
		$mailFileHeader="";
226 liveuser 1589
 
3 liveuser 1590
		#依據 $conf["receiverMail"] 的數量
1591
		for($i=0;$i<count($conf["receiverMail"]);$i++){
226 liveuser 1592
 
3 liveuser 1593
			#串接寄件人的資訊
1594
			$mailFileHeader=$mailFileHeader.$fromInfo;
226 liveuser 1595
 
3 liveuser 1596
			#如果第$i筆信件的收件人陣列不存在
1597
			if(!isset($conf["receiverMail"][$i])){
226 liveuser 1598
 
3 liveuser 1599
				#設置執行不正常
1600
				$result["status"]="false";
226 liveuser 1601
 
3 liveuser 1602
				#設置錯誤訊息
1603
				$result["error"][]="第".($i+1)."筆收件人陣列不存在";
226 liveuser 1604
 
3 liveuser 1605
				#回傳結果
1606
				return $result;
226 liveuser 1607
 
3 liveuser 1608
				}#if end
1609
 
1610
			#反之存在但形態不為陣列
1611
			if(gettype($conf["receiverMail"][$i])!="array"){
226 liveuser 1612
 
3 liveuser 1613
				#設置執行不正常
1614
				$result["status"]="false";
226 liveuser 1615
 
3 liveuser 1616
				#設置錯誤訊息
1617
				$result["error"][]="第".($i+1)."筆收件人陣列形態不正確";
226 liveuser 1618
 
3 liveuser 1619
				#回傳結果
1620
				return $result;
226 liveuser 1621
 
1622
				}#if end
1623
 
3 liveuser 1624
			#如果第$i筆信件的收件人名稱不存在
1625
			if(!isset($conf["receiverNameDisplay"][$i])){
226 liveuser 1626
 
3 liveuser 1627
				#設為第$i筆信件的收件人陣列
1628
				$conf["receiverNameDisplay"][$i]=$conf["receiverMail"][$i];
226 liveuser 1629
 
3 liveuser 1630
				}#if end
226 liveuser 1631
 
3 liveuser 1632
			#第$i筆信件收件人名稱陣列的第一個元素不存在
1633
			else if(!isset($conf["receiverNameDisplay"][$i][0])){
226 liveuser 1634
 
3 liveuser 1635
				#設置執行不正常
1636
				$result["status"]="false";
226 liveuser 1637
 
3 liveuser 1638
				#設置錯誤訊息
1639
				$result["error"][]="第".($i+1)."筆收件人名稱陣列的第一個收件人名稱不存在";
226 liveuser 1640
 
3 liveuser 1641
				#回傳結果
1642
				return $result;
226 liveuser 1643
 
3 liveuser 1644
				}#if end
226 liveuser 1645
 
3 liveuser 1646
			#如果第$i筆信件的收件人信箱名稱不存在
1647
			if(!isset($conf["receiverMailDisplay"][$i])){
226 liveuser 1648
 
3 liveuser 1649
				#設為第$i筆信件的收件人陣列
1650
				$conf["receiverMailDisplay"][$i]=$conf["receiverMail"][$i];
226 liveuser 1651
 
3 liveuser 1652
				}#if end
226 liveuser 1653
 
3 liveuser 1654
			#第$i筆信件收件人信箱名稱陣列的第一個元素不存在
1655
			else if(!isset($conf["receiverNameDisplay"][$i][0])){
226 liveuser 1656
 
3 liveuser 1657
				#設置執行不正常
1658
				$result["status"]="false";
226 liveuser 1659
 
3 liveuser 1660
				#設置錯誤訊息
1661
				$result["error"][]="第".($i+1)."筆收件人信箱名稱陣列的第一個收件人信箱名稱不存在";
226 liveuser 1662
 
3 liveuser 1663
				#回傳結果
1664
				return $result;
226 liveuser 1665
 
1666
				}#if end
1667
 
3 liveuser 1668
			#第一個人為主要收件人
226 liveuser 1669
			$mailFileHeader=$mailFileHeader."To: ".$conf["receiverNameDisplay"][$i][0]." "."<".$conf["receiverMailDisplay"][$i][0].">\r\n";
1670
 
3 liveuser 1671
			#如果有其餘收件人
1672
			if(count($conf["receiverNameDisplay"][$i])>1){
226 liveuser 1673
 
3 liveuser 1674
				#副本寄送處的資訊開始
1675
				$mailFileHeader=$mailFileHeader."Cc: ";
226 liveuser 1676
 
3 liveuser 1677
				}#if end
226 liveuser 1678
 
3 liveuser 1679
			#針對其餘收件人的地址
1680
			for($j=1;$j<count($conf["receiverNameDisplay"][$i]);$j++){
226 liveuser 1681
 
3 liveuser 1682
				#如果不是最後一筆
1683
				if($j!=count($conf["receiverNameDisplay"][$i])-1){
226 liveuser 1684
 
3 liveuser 1685
					#串接並加上逗號
1686
					$mailFileHeader=$mailFileHeader.$conf["receiverNameDisplay"][$i][$j]." <".$conf["receiverMailDisplay"][$i][$j].">,";
226 liveuser 1687
 
3 liveuser 1688
					}#if end
226 liveuser 1689
 
3 liveuser 1690
				#反之是最後一筆
1691
				else{
226 liveuser 1692
 
3 liveuser 1693
					#串接並接上換行符號
1694
					$mailFileHeader=$mailFileHeader.$conf["receiverNameDisplay"][$i][$j]." <".$conf["receiverMailDisplay"][$i][$j].">\r\n";
226 liveuser 1695
 
1696
					}#else end
1697
 
3 liveuser 1698
				}#for end
226 liveuser 1699
 
3 liveuser 1700
			#設置信件標題
1701
			$mailFileHeader=$mailFileHeader."Subject: ".$conf["subject"][$i]."\r\n";
226 liveuser 1702
 
3 liveuser 1703
			#設置 MIME-Version
1704
			$mailFileHeader=$mailFileHeader."MIME-Version: 1.0\r\n";
226 liveuser 1705
 
3 liveuser 1706
			#初始化信件本文
1707
			$mailFileContent="";
226 liveuser 1708
 
1709
			#設置信件本文(純文字與html兩種)
3 liveuser 1710
			$mailFileContent=$mailFileContent."--001a11c30ce8aec3550533bfa9ab\r\n";
1711
			$mailFileContent=$mailFileContent."Content-Type: multipart/alternative; boundary=001a11c30ce8aec3480533bfa9a9\r\n";
1712
			$mailFileContent=$mailFileContent."\r\n";
1713
			$mailFileContent=$mailFileContent."--001a11c30ce8aec3480533bfa9a9\r\n";
1714
			$mailFileContent=$mailFileContent."Content-Type: text/plain; charset=UTF-8\r\n";
1715
			$mailFileContent=$mailFileContent."\r\n";
1716
			$mailFileContent=$mailFileContent.$conf["plainBody"][$i]."\r\n";
1717
			$mailFileContent=$mailFileContent."\r\n";
1718
			$mailFileContent=$mailFileContent."--001a11c30ce8aec3480533bfa9a9\r\n";
1719
			$mailFileContent=$mailFileContent."Content-Type: text/html; charset=UTF-8\r\n";
1720
			$mailFileContent=$mailFileContent."\r\n";
1721
			$mailFileContent=$mailFileContent.$conf["htmlBody"][$i]."\r\n";
1722
			$mailFileContent=$mailFileContent."\r\n";
1723
			$mailFileContent=$mailFileContent."--001a11c30ce8aec3480533bfa9a9--\r\n";
226 liveuser 1724
 
3 liveuser 1725
			#如果有設定要上傳附件
1726
			if(isset($conf["attachment"])){
226 liveuser 1727
 
3 liveuser 1728
				#如果第 $i+1 封信件有指定 附件
1729
				if(isset($conf["attachment"][$i])){
226 liveuser 1730
 
3 liveuser 1731
					#如果類型正確
1732
					if(gettype($conf["attachment"][$i])=="array"){
226 liveuser 1733
 
3 liveuser 1734
						#依據每個附件
1735
						for($j=0;$j<count($conf["attachment"][$i]);$j++){
226 liveuser 1736
 
3 liveuser 1737
							#初始化寄送附件的語法
1738
							$attachment="";
226 liveuser 1739
 
1740
							#確認目標檔案是否存在 #函式說明:檢查多個檔案是否存在 #回傳的結果:
1741
							#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
1742
							#$result["error"],錯誤訊息陣列.
1743
							#$resutl["function"],當前執行的涵式名稱.
1744
							#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
1745
							#$result["varName"][$i],爲第$i個資料夾或檔案的名稱。
1746
							#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
1747
							#必填參數:
1748
							$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
1749
							$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($conf["attachment"][$i][$j]);#要檢查書否存在的檔案有哪些,須爲一維陣列數值。
1750
							#參考資料來源:
1751
							#http://php.net/manual/en/function.file-exists.php
1752
							#http://php.net/manual/en/control-structures.foreach.php
1753
							$checkMutiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
3 liveuser 1754
							unset($conf["fileAccess::checkMultiFileExist"]);
226 liveuser 1755
 
3 liveuser 1756
							#如果檢查失敗
1757
							if($checkMutiFileExist["status"]=="false"){
226 liveuser 1758
 
3 liveuser 1759
								#設置錯誤識別
1760
								$result["status"]="false";
1761
 
1762
								#設置錯誤資訊
1763
								$result["error"]=$checkMutiFileExist;
1764
 
1765
								#回傳結果
1766
								return $result;
226 liveuser 1767
 
3 liveuser 1768
								}#if end
226 liveuser 1769
 
3 liveuser 1770
							#如果檔案不存在
1771
							if($checkMutiFileExist["varExist"][0]=="false"){
226 liveuser 1772
 
3 liveuser 1773
								#設置錯誤識別
1774
								$result["status"]="false";
1775
 
1776
								#設置錯誤資訊
1777
								$result["error"]=$checkMutiFileExist;
1778
 
1779
								#回傳結果
1780
								return $result;
226 liveuser 1781
 
3 liveuser 1782
								}#if end
226 liveuser 1783
 
3 liveuser 1784
							#如果是第一個附件
1785
							if($j==0){
226 liveuser 1786
 
3 liveuser 1787
								#在前面加上 multipart/mixed 的 boundary
1788
								$mailFileContent="Content-Type: multipart/mixed; boundary=001a11c30ce8aec3550533bfa9ab\r\n\r\n".$mailFileContent;
226 liveuser 1789
 
3 liveuser 1790
								}#if end
226 liveuser 1791
 
3 liveuser 1792
							#如果 $conf["attachmentName"][$i] 不存在
1793
							if(!isset($conf["attachmentName"][$i])){
226 liveuser 1794
 
3 liveuser 1795
								#涵是說明:
1796
								#取得檔案路徑字串的路徑與檔案的名稱與檔案副檔名
1797
								#回傳的結果:
1798
								#$result["status"],執行是否正常,"true"正常,"false"代表不正常.
1799
								#$result["error"],錯誤訊息.
1800
								#$result["function"],當前執行的函式名稱.
1801
								#$result["filePath"],路徑字串.
1802
								#$result["fileName"],檔案名稱字串.
1803
								#$result["fileExtention"],檔案的副檔名.
1804
								#$result["fullFileName"],含副檔名的檔案名稱.
1805
								#$result["fullFilePathAndName"],完整的檔案路徑(含副檔名).
1806
								#必填參數:
1807
								#$conf["fileAddressAndName"],字串,檔案名稱與其路徑.
1808
								$conf["fileAccess::getFileAddressAndNameAndFileExtention"]["fileAddressAndName"]=$conf["attachment"][$i][$j];
1809
								#可省略的參數:
1810
								#無.
1811
								$getFileAddressAndNameAndFileExtention=fileAccess::getFileAddressAndNameAndFileExtention($conf["fileAccess::getFileAddressAndNameAndFileExtention"]);
1812
								unset($conf["fileAccess::getFileAddressAndNameAndFileExtention"]);
226 liveuser 1813
 
1814
								#如果解析檔案資訊失敗
3 liveuser 1815
								if($getFileAddressAndNameAndFileExtention["status"]=="false"){
226 liveuser 1816
 
3 liveuser 1817
									#設置錯誤識別
1818
									$result["status"]="false";
1819
 
1820
									#設置錯誤資訊
1821
									$result["error"]=$getFileAddressAndNameAndFileExtention;
1822
 
1823
									#回傳結果
1824
									return $result;
226 liveuser 1825
 
1826
									}#if end
1827
 
3 liveuser 1828
								#設定附件名稱
1829
								$conf["attachmentName"][$i][$j]=$getFileAddressAndNameAndFileExtention["fullFileName"];
226 liveuser 1830
 
3 liveuser 1831
								}#if end
226 liveuser 1832
 
3 liveuser 1833
							#反之如果 $conf["attachmentName"][$i][$j] 不存在
1834
							else if(!isset($conf["attachmentName"][$i][$j])){
226 liveuser 1835
 
3 liveuser 1836
								#涵是說明:
1837
								#取得檔案路徑字串的路徑與檔案的名稱與檔案副檔名
1838
								#回傳的結果:
1839
								#$result["status"],執行是否正常,"true"正常,"false"代表不正常.
1840
								#$result["error"],錯誤訊息.
1841
								#$result["function"],當前執行的函式名稱.
1842
								#$result["filePath"],路徑字串.
1843
								#$result["fileName"],檔案名稱字串.
1844
								#$result["fileExtention"],檔案的副檔名.
1845
								#$result["fullFileName"],含副檔名的檔案名稱.
1846
								#$result["fullFilePathAndName"],完整的檔案路徑(含副檔名).
1847
								#必填參數:
1848
								#$conf["fileAddressAndName"],字串,檔案名稱與其路徑.
1849
								$conf["fileAccess::getFileAddressAndNameAndFileExtention"]["fileAddressAndName"]=$conf["attachment"][$i][$j];
1850
								#可省略的參數:
1851
								#無.
1852
								$getFileAddressAndNameAndFileExtention=fileAccess::getFileAddressAndNameAndFileExtention($conf["fileAccess::getFileAddressAndNameAndFileExtention"]);
1853
								unset($conf["fileAccess::getFileAddressAndNameAndFileExtention"]);
226 liveuser 1854
 
1855
								#如果解析檔案資訊失敗
3 liveuser 1856
								if($getFileAddressAndNameAndFileExtention["status"]=="false"){
226 liveuser 1857
 
3 liveuser 1858
									#設置錯誤識別
1859
									$result["status"]="false";
1860
 
1861
									#設置錯誤資訊
1862
									$result["error"]=$getFileAddressAndNameAndFileExtention;
1863
 
1864
									#回傳結果
1865
									return $result;
226 liveuser 1866
 
1867
									}#if end
1868
 
3 liveuser 1869
								#設定附件名稱
1870
								$conf["attachmentName"][$i][$j]=$getFileAddressAndNameAndFileExtention["fullFileName"];
226 liveuser 1871
 
3 liveuser 1872
								}#if end
226 liveuser 1873
 
3 liveuser 1874
							#如果 $conf["attachmentMimeType"][$i][$j] 不存在
1875
							if(!isset($conf["attachmentMimeType"][$i])){
226 liveuser 1876
 
3 liveuser 1877
								#設定檔案類型
1878
								$conf["attachmentMimeType"][$i][$j]="application/*";
226 liveuser 1879
 
1880
								}#if end
1881
 
1882
							#反之如果 $conf["attachmentMimeType"][$i][$j] 不存在
3 liveuser 1883
							else if(!isset($conf["attachmentMimeType"][$i][$j])){
226 liveuser 1884
 
3 liveuser 1885
								$conf["attachmentMimeType"][$i][$j]="application/*";
226 liveuser 1886
 
3 liveuser 1887
								}#if end
226 liveuser 1888
 
3 liveuser 1889
							#加上寄送附件的語法
1890
							$attachment=$attachment."--001a11c30ce8aec3550533bfa9ab\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";
226 liveuser 1893
							$attachment=$attachment."Content-Transfer-Encoding: base64\r\n";
3 liveuser 1894
							$attachment=$attachment."X-Attachment-Id: f_io1ikfii".$i."_".$j."\r\n";
226 liveuser 1895
 
1896
							#將檔案用base64加密
3 liveuser 1897
							$base64fileStr=base64_encode(file_get_contents($conf["attachment"][$i][$j]));
226 liveuser 1898
 
3 liveuser 1899
							#依據規定,每列不得大於70的字元
1900
							$wordwrapedFileStr=wordwrap($base64fileStr,70,"\r\n",true);
226 liveuser 1901
 
3 liveuser 1902
							#斷行後附加檔案字串
226 liveuser 1903
							$attachment=$attachment."\r\n".$wordwrapedFileStr."\r\n";
1904
 
3 liveuser 1905
							#如果是最後一個附件
1906
							if($j==count($conf["attachment"][$i])-1){
226 liveuser 1907
 
3 liveuser 1908
								#混合資料結尾
1909
								$attachment=$attachment."--001a11c30ce8aec3550533bfa9ab--\r\n";
226 liveuser 1910
 
1911
								}#if end
1912
 
3 liveuser 1913
							#增加到信件內文的結尾
1914
							$mailFileContent=$mailFileContent.$attachment;
226 liveuser 1915
 
3 liveuser 1916
							}#for end
226 liveuser 1917
 
3 liveuser 1918
						}#if end
226 liveuser 1919
 
3 liveuser 1920
					}#if end
226 liveuser 1921
 
3 liveuser 1922
				}#if end
226 liveuser 1923
 
3 liveuser 1924
			#要寄送的郵件檔案路徑與名稱
226 liveuser 1925
			$mailFile=".curlSmtp/mail_at_".$systemTime.".mail";
1926
 
3 liveuser 1927
			#建立要寄送的郵件檔案
1928
			#將字串寫入到檔案
1929
			#回傳結果:
1930
			#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
1931
			#$result["error"],錯誤訊息陣列.
1932
			#$result["function"],當前執行的函數名稱.
1933
			#$result["fileInfo"],實際上寫入的檔案資訊陣列.
1934
			#$result["fileInfo"]["createdFileName"],建立好的檔案名稱.
1935
			#$result["fileInfo"]["createdFilePath"],檔案建立的路徑.
1936
			#$result["fileInfo"]["createdFilePathAndName"].建立好的檔案名稱與路徑.
1937
			#必填參數:
1938
			$conf["fileAccess::writeTextIntoFile"]["fileName"]=$mailFile;#爲要編輯的檔案名稱
1939
			$conf["fileAccess::writeTextIntoFile"]["inputString"]=$mailFileHeader.$mailFileContent;#爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可。
1940
			$conf["fileAccess::writeTextIntoFile"]["fileArgu"]=$conf["fileArgu"];
1941
			#可省略參數:
1942
			#$conf["writeMethod"],字串,爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入.
1943
			#$conf["writeMethod"]="a";
1944
			#$conf["checkRepeat"],字串,"true"代表建立檔案之前要先檢查檔案是否存在,若存在則在原名稱後面加上從(1)開始的編號.
1945
			$conf["fileAccess::writeTextIntoFile"]["checkRepeat"]="true";
1946
			#$conf["filenameExtensionStartPoint"],字串,檔案的副檔名是從倒數第幾個小數點(dot)開始,預設為"1",最後一個小數點
1947
			#$conf["filenameExtensionStartPoint"]="";
1948
			#$conf["repeatNameRule"],字串,遇到相同名稱的檔案要如何加上識別的編號,編號用「\$i」表示,預設為"(\$i)"
1949
			$conf["fileAccess::writeTextIntoFile"]["repeatNameRule"]="_\$i";
1950
			$writeTextIntoFile=fileAccess::writeTextIntoFile($conf["fileAccess::writeTextIntoFile"]);
1951
			unset($conf["fileAccess::writeTextIntoFile"]);
226 liveuser 1952
 
3 liveuser 1953
			#如果檔案建立失敗
1954
			if($writeTextIntoFile["status"]=="false"){
1955
 
1956
				#設置錯誤識別
1957
				$result["status"]="false";
1958
 
1959
				#設置錯誤資訊
1960
				$result["error"]=$writeTextIntoFile;
1961
 
1962
				#回傳結果
1963
				return $result;
1964
 
1965
				}#if end
226 liveuser 1966
 
3 liveuser 1967
			#取得建立好的檔案名稱
1968
			$mailFile=$writeTextIntoFile["fileInfo"]["createdFilePathAndName"];
226 liveuser 1969
 
3 liveuser 1970
			#初始化收件人字串
1971
			$rcptStr="";
1972
 
1973
			#有幾個收件人就執行幾次
1974
			foreach($conf["receiverMail"][$i] as $mailTo){
226 liveuser 1975
 
3 liveuser 1976
				#串接收件人
1977
				$rcptStr=$rcptStr." --mail-rcpt \"".$mailTo."\"";
226 liveuser 1978
 
3 liveuser 1979
				}#for end
1980
 
1981
			#初始化允許不安全連線的字串
1982
			$insecure="";
1983
 
1984
			#如果允許不安全的連線
1985
			if($conf["insecure"]==="true"){
226 liveuser 1986
 
3 liveuser 1987
				#設置允許不安全連線
1988
				$insecure="--insecure";
226 liveuser 1989
 
3 liveuser 1990
				}#if end
1991
 
1992
			#如果登入帳號不用@
1993
			if($conf["usernameOnly"]==="true"){
226 liveuser 1994
 
3 liveuser 1995
				#尋找有無 "@"
1996
				$at=strpos($conf["username"],"@");
226 liveuser 1997
 
3 liveuser 1998
				#如果有找到
1999
				if($at!==false){
226 liveuser 2000
 
3 liveuser 2001
					#取得不含 @... 的帳戶名稱
2002
					$conf["username"]=substr($conf["username"],0,$at);
226 liveuser 2003
 
3 liveuser 2004
					}#if end
226 liveuser 2005
 
3 liveuser 2006
				}#if end
2007
 
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";
226 liveuser 2010
 
3 liveuser 2011
			#取得寄信的指令
226 liveuser 2012
			$mailCmdArray[]=$cmdString;
2013
 
3 liveuser 2014
			#取得移除信件檔案的指令
2015
			$delMailFileCmd[]="rm \"".$mailFile."\"";
226 liveuser 2016
 
3 liveuser 2017
			#清空 $mailFileHeader
2018
			$mailFileHeader="";
226 liveuser 2019
 
48 liveuser 2020
			}#for end
226 liveuser 2021
 
3 liveuser 2022
		#用curl寄送信件
2023
		#函式說明:
2024
		#運用nohup與&來達到雖依序執行但不等待前一個指令執行完再執行下一個指令,形成假多工的執行每個指令.
226 liveuser 2025
		#回傳結果:
3 liveuser 2026
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2027
		#$result["error"],錯誤訊息陣列.
2028
		#$result["function"],當前執行的函數名稱.
2029
		#$result["cmd"],執行的指令內容.
2030
		#$result["output"],爲執行完二元碼後的輸出陣列.
2031
		#必填參數:
2032
		#$conf["command"],字串陣列,要執行的指令與.
2033
		$conf["external::multiThreadsShell"]["command"]=$mailCmdArray;
2034
		#$conf["fileArgu"],字串,變數__FILE__的內容.
226 liveuser 2035
		$conf["external::multiThreadsShell"]["fileArgu"]=$conf["fileArgu"];
3 liveuser 2036
		#可省略參數:
2037
		#$conf["argu"],二維陣列字串,每個指令搭配的參數,預設為空陣列.
2038
		#$conf["argu"]=array(array());
2039
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
2040
		#$conf["enablePrintDescription"]="true";
2041
		#$conf["printDescription"],字串陣列,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
2042
		#$conf["printDescription"]=array("");
2043
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
2044
		#$conf["escapeshellarg"]="false";
2045
		#$conf["username"],字串陣列,每個指令要用什麼使用者來執行,預設為執行php使用者,該參數不適用於apache環境.
2046
		#$conf["username"]=array("");
2047
		#$conf["password"],字串陣列,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
2048
		#$conf["password"]=array("");
2049
		$multiThreadsShell=external::multiThreadsShell($conf["external::multiThreadsShell"]);
2050
		unset($conf["external::multiThreadsShell"]);
226 liveuser 2051
 
3 liveuser 2052
		#如果寄信失敗
48 liveuser 2053
		if($multiThreadsShell["status"]=="false"){
226 liveuser 2054
 
3 liveuser 2055
			#設置錯誤識別
2056
			$result["status"]="false";
2057
 
2058
			#設置錯誤資訊
2059
			$result["error"]=$multiThreadsShell;
2060
 
2061
			#回傳結果
2062
			return $result;
226 liveuser 2063
 
48 liveuser 2064
			}#if end
226 liveuser 2065
 
3 liveuser 2066
		#取得執行的指令
2067
		$result["cmd"]=$multiThreadsShell["cmd"];
226 liveuser 2068
 
3 liveuser 2069
		/*
2070
		#移除信件檔案
2071
		#函式說明:
2072
		#運用nohup與&來達到雖依序執行但不等待前一個指令執行完再執行下一個指令,形成假多工的執行每個指令.
226 liveuser 2073
		#回傳結果:
3 liveuser 2074
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2075
		#$result["error"],錯誤訊息陣列.
2076
		#$result["function"],當前執行的函數名稱.
2077
		#$result["cmd"],執行的指令內容.
2078
		#$result["output"],爲執行完二元碼後的輸出陣列.
2079
		#必填參數:
2080
		#$conf["command"],字串陣列,要執行的指令與.
2081
		$conf["external::multiThreadsShell"]["command"]=$delMailFileCmd;
2082
		#$conf["fileArgu"],字串,變數__FILE__的內容.
226 liveuser 2083
		$conf["external::multiThreadsShell"]["fileArgu"]=$conf["fileArgu"];
3 liveuser 2084
		#可省略參數:
2085
		#$conf["argu"],二維陣列字串,每個指令搭配的參數,預設為空陣列.
2086
		#$conf["argu"]=array(array());
2087
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
2088
		#$conf["enablePrintDescription"]="true";
2089
		#$conf["printDescription"],字串陣列,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
2090
		#$conf["printDescription"]=array("");
2091
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
2092
		#$conf["escapeshellarg"]="false";
2093
		#$conf["username"],字串陣列,每個指令要用什麼使用者來執行,預設為執行php使用者,該參數不適用於apache環境.
2094
		#$conf["username"]=array("");
2095
		#$conf["password"],字串陣列,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
2096
		#$conf["password"]=array("");
2097
		$multiThreadsShell=external::multiThreadsShell($conf["external::multiThreadsShell"]);
2098
		unset($conf["external::multiThreadsShell"]);
226 liveuser 2099
 
3 liveuser 2100
		#如果移除信件檔案失敗
2101
		if($multiThreadsShell["status"]=="false"){
226 liveuser 2102
 
3 liveuser 2103
			#設置錯誤識別
2104
			$result["status"]="false";
2105
 
2106
			#設置錯誤資訊
2107
			$result["error"]=$multiThreadsShell;
2108
 
2109
			#回傳結果
2110
			return $result;
226 liveuser 2111
 
3 liveuser 2112
			}
226 liveuser 2113
 
48 liveuser 2114
		*/
226 liveuser 2115
 
3 liveuser 2116
		#設置執行正常
2117
		$result["status"]="true";
226 liveuser 2118
 
3 liveuser 2119
		#回傳結果
2120
		return $result;
226 liveuser 2121
 
3 liveuser 2122
		}#function multiCurlSmtp end
226 liveuser 2123
 
3 liveuser 2124
	/*
2125
	#函式說明:
2126
	#透過php的mail函數寄信
2127
	#回傳結果:
2128
	#$result["status"],寄信的情況,若爲"true",則十之八九沒有問題.
2129
	#$result["error"],錯誤訊息陣列
2130
	#$result["function"],當前執行的函數
2131
	#必填參數:
2132
	#$conf["to"],字串陣列,收件人們的信箱.
2133
	$conf["to"]=array();
2134
	#$conf["subject"],字串,郵件標題.
2135
	$conf["subject"]="";
2136
	#$conf["content"],字串,要寄送的訊息內容.
2137
	$conf["content"]="";
226 liveuser 2138
	#可省略參數:
3 liveuser 2139
	#$conf["mailerEmail"],字串,顯示的寄件人.
2140
	#$conf["mailerEmail"]="";
2141
	#參考資料:
2142
	#mail=>https://www.php.net/manual/en/function.mail.php
2143
	#Internet Message Format=>http://www.faqs.org/rfcs/rfc2822
2144
	#備註:
2145
	#無.
2146
	*/
2147
	public static function sendMail(&$conf){
226 liveuser 2148
 
3 liveuser 2149
		#初始化要回傳的結果
2150
		$result=array();
2151
 
2152
		#儲存當前執行的函數
2153
		$result["function"]=__FUNCTION__;
2154
 
2155
		#如果 $conf 不為陣列
2156
		if(gettype($conf)!="array"){
226 liveuser 2157
 
3 liveuser 2158
			#設置執行失敗
2159
			$result["status"]="false";
226 liveuser 2160
 
3 liveuser 2161
			#設置執行錯誤訊息
2162
			$result["error"][]="\$conf變數須為陣列形態";
2163
 
2164
			#如果傳入的參數為 null
2165
			if($conf==null){
226 liveuser 2166
 
3 liveuser 2167
				#設置執行錯誤訊息
2168
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 2169
 
3 liveuser 2170
				}#if end
2171
 
2172
			#回傳結果
2173
			return $result;
226 liveuser 2174
 
3 liveuser 2175
			}#if end
226 liveuser 2176
 
3 liveuser 2177
		#檢查參數
2178
		#函式說明:
2179
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
2180
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2181
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
2182
		#$result["function"],當前執行的函式名稱.
2183
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
2184
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
2185
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
2186
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
2187
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
2188
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
2189
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
2190
		#必填寫的參數:
2191
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
2192
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
2193
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
2194
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("to","subject","content");
226 liveuser 2195
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
3 liveuser 2196
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array","string","string");
2197
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
2198
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
2199
		#可以省略的參數:
2200
		#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
2201
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
2202
		#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
2203
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("mailerEmail");
226 liveuser 2204
		#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 2205
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
2206
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
2207
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null);
2208
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
2209
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("subject","plainBody","htmlBody","receiverMail","receiverMailDisplay","receiverNameDisplay");
2210
		#參考資料來源:
2211
		#array_keys=>http://php.net/manual/en/function.array-keys.php
2212
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
2213
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 2214
 
3 liveuser 2215
		#如果檢查失敗
2216
		if($checkArguments["status"]=="false"){
226 liveuser 2217
 
3 liveuser 2218
			#設置錯誤識別
2219
			$result["status"]="false";
226 liveuser 2220
 
3 liveuser 2221
			#設置錯誤訊息
2222
			$result["error"]=$checkArguments;
226 liveuser 2223
 
3 liveuser 2224
			#回傳結果
2225
			return $result;
226 liveuser 2226
 
3 liveuser 2227
			}#if end
226 liveuser 2228
 
3 liveuser 2229
		#如果檢查不通過
2230
		if($checkArguments["passed"]=="false"){
226 liveuser 2231
 
3 liveuser 2232
			#設置錯誤識別
2233
			$result["status"]="false";
226 liveuser 2234
 
3 liveuser 2235
			#設置錯誤訊息
2236
			$result["error"]=$checkArguments;
226 liveuser 2237
 
3 liveuser 2238
			#回傳結果
2239
			return $result;
226 liveuser 2240
 
3 liveuser 2241
			}#if end
226 liveuser 2242
 
3 liveuser 2243
		#函式說明:
2244
		#將一維陣列轉換為用特定符號間隔的字串,ex:array("1","2","3") to "a;b;c;".
2245
		#回傳的結果:
2246
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2247
		#$result["function"],當前執行的function名稱
2248
		#$result["error"],錯誤訊息陣列.
2249
		#$result["content"],處理好的字串.
2250
		#$result["argu"],使用的參數.
2251
		#必填參數:
2252
		#$conf["inputArray"],字串陣列,要轉成字串的一維陣列.
2253
		$conf["arrays::arrayToString"]["inputArray"]=$conf["to"];
2254
		#可省略參數:
2255
		#$conf["spiltSymbol"],字串,用來區隔字串的符號,預設為;
2256
		$conf["arrays::arrayToString"]["spiltSymbol"]=", ";
2257
		#$conf["skipEnd"],字串,結尾是否不要加上符號,預設為"false",要加上符號,"true"代表不要加上符號。
2258
		$conf["arrays::arrayToString"]["skipEnd"]="true";
2259
		#參考資料:
2260
		#無.
2261
		#備註:
2262
		#無.
2263
		$arrayToString=arrays::arrayToString($conf["arrays::arrayToString"]);
2264
		unset($conf["arrays::arrayToString"]);
226 liveuser 2265
 
3 liveuser 2266
		#如果檢查失敗
2267
		if($arrayToString["status"]=="false"){
226 liveuser 2268
 
3 liveuser 2269
			#設置錯誤識別
2270
			$result["status"]="false";
226 liveuser 2271
 
3 liveuser 2272
			#設置錯誤訊息
2273
			$result["error"]=$arrayToString;
226 liveuser 2274
 
3 liveuser 2275
			#回傳結果
2276
			return $result;
226 liveuser 2277
 
3 liveuser 2278
			}#if end
226 liveuser 2279
 
3 liveuser 2280
		$to = $arrayToString["content"];
2281
		$subject = $conf["subject"];
2282
		$message = $conf["content"];
226 liveuser 2283
 
3 liveuser 2284
		# In case any of our lines are larger than 70 characters, we should use wordwrap()
2285
		$message = wordwrap($message, 70, "\r\n");
226 liveuser 2286
 
3 liveuser 2287
		#初始化mail header為空
2288
		$headers = "";
226 liveuser 2289
 
3 liveuser 2290
		#如果有設置寄件人資訊
2291
		if(isset($conf["mailerEmail"])){
226 liveuser 2292
 
3 liveuser 2293
			#設置寄件人資訊
2294
			$headers = "From: ".$conf["mailerEmail"];
226 liveuser 2295
 
3 liveuser 2296
			}#if end
226 liveuser 2297
 
3 liveuser 2298
		#寄信
2299
		$mailResult=mail($to, $subject, $message, $headers);
226 liveuser 2300
 
3 liveuser 2301
		#初始化執行正常
226 liveuser 2302
		$result["status"]="true";
2303
 
3 liveuser 2304
		#如果寄信失敗
2305
		if(!$mailResult){
226 liveuser 2306
 
3 liveuser 2307
			#設置執行不正常
2308
			$result["status"]="false";
226 liveuser 2309
 
3 liveuser 2310
			#回傳結果
2311
			return $result;
226 liveuser 2312
 
3 liveuser 2313
			}#if end
226 liveuser 2314
 
3 liveuser 2315
		#回傳結果
226 liveuser 2316
		return $result;
2317
 
3 liveuser 2318
		}#function sendMail end
226 liveuser 2319
 
48 liveuser 2320
	/*
2321
	#函式說明:
2322
	#使用 php-pear-smtp 來透過SMTP伺服器寄信.
2323
	#回傳結果:
2324
	#$result["status"],執行正常與否,"true"代表正常;反之為"false".
2325
	#$result["error"],錯誤訊息陣列
2326
	#$result["function"],當前執行的函數.
2327
	#必填參數:
58 liveuser 2328
	#$conf["mailServer"],字串,要使用的SMTP郵件伺服器網址.若為tls加密,開頭請輸入"ssl://".
48 liveuser 2329
	$conf["mailServer"]="";
2330
	#$conf["username"],字串,用來登入郵件伺服器的帳號
2331
	$conf["username"]="";
2332
	#$conf["password"],字串,用來登入郵件伺服器的密碼
2333
	$conf["password"]="";
2334
	#$conf["receiverMail"],陣列,收件人的信箱
2335
	$conf["receiverMail"]=array("");
2336
	#$conf["subject"],字串,郵件的主題
2337
	$conf["subject"]="";
2338
	#$conf["plainBody"],字串,郵件本文的純文字內容.
2339
	$conf["plainBody"]="";
2340
	#$conf["htmlBody"]="";,字串,郵件本文的html內容,多媒體盡量不要用base64的方式來嵌入,因為大部分的郵件服務(Gmail)都不支援,如果是在單機上的郵件軟體就可能有支援,例如:Evolution.
2341
	$conf["htmlBody"]="";
2342
	#可省略參數:
2343
	#$conf["mailServerPort"],整數,smtp server的port,預設為465.
2344
	#$conf["mailServerPort"]=465;
2345
	#$conf["mailerMailDisplay"],字串,要顯示的寄件人信箱,預設爲 $conf["username"]
2346
	#$conf["mailerMailDisplay"]="";
2347
	#$conf["mailerNameDisplay"],字串,要顯示的寄件人姓名,預設爲 $conf["username"]
2348
	#$conf["mailerNameDisplay"]="";
2349
	#$conf["receiverNameDisplay"],陣列,要顯示的收件人姓名,預設爲 $conf["receiverMail"] 對應的元素.
58 liveuser 2350
	#$conf["receiverNameDisplay"]=array();
48 liveuser 2351
	#$conf["attachment"],陣列,每個要寄送的附件路徑與檔案名稱
2352
	#$conf["attachment"]=array();
2353
	#$conf["attachmentName"],陣列,每個要寄送的附件顯示名稱,預設為$conf["attachment"]中的實際檔案名稱.
2354
	#$conf["attachmentName"]=array();
2355
	#$conf["attachmentMimeType"],陣列,每個附件的 mimeType,預設為"application/*".
237 liveuser 2356
	#$conf["attachmentMimeType"]=array();
48 liveuser 2357
	#$conf["userAgent"],字串,用於表示使用smtp服務的軟體資訊,預設為"Powerd by QBPWCF(https://lib.qbpwcf.org)".
2358
	#$conf["userAgent"]="Powerd by QBPWCF(https://lib.qbpwcf.org)";
2359
	#$conf["org"],字串,若要表示來源組織名稱,可在此設定.
2360
	#$conf["org"]="";
2361
	#$conf["notifyReceived"],字串,回報已讀通知,預設為"true"代表要;反之為"false".
2362
	#$conf["notifyReceived"]="true";
2363
	#$conf["signWithGPGid"],字串,用於簽署的gpg id,預設不使用.
2364
	#$conf["signWithGPGid"]="";
237 liveuser 2365
	#$conf["signGpgThroughSocket"],字串,"true"代表簽署gpg id的操作透過qbpwcf-uscok.service處理;預設為"false",直接用執行本程式的使用者來執行.
2366
	#$conf["signGpgThroughSocket"]="false";
2367
	#$conf["gpgPrivateKeyUser"],字串,當參數"signGpgThroughSocket"為"true"時,需要切換到哪個使用者才能取得gpg private key,預設使用運行qbpwcf-uscok.service的使用者.
2368
	#$conf["gpgPrivateKeyUser"]="";
48 liveuser 2369
	#參考資料:
2370
	#官網=>http://pear.php.net/package/Net_SMTP
2371
	#Document=>https://github.com/pear/Net_SMTP
2372
	#SSL=>https://github.com/pear/Net_SMTP?tab=readme-ov-file#secure-connections
2373
	#Message-ID: =>https://datatracker.ietf.org/doc/html/rfc5322
2374
	#mail body boundary=>https://www.w3.org/Protocols/rfc1341/7_2_Multipart.html
2375
	#備註:
2376
	#需要php-pear-Net-SMTP
2377
	*/
2378
	public static function pear_smtp_send(&$conf){
226 liveuser 2379
 
48 liveuser 2380
		#初始化要回傳的結果
2381
		$result=array();
2382
 
2383
		#取得當前執行的函數名稱
2384
		$result["function"]=__FUNCTION__;
2385
 
2386
		#如果沒有參數
2387
		if(func_num_args()==0){
2388
 
2389
			#設置執行失敗
2390
			$result["status"]="false";
2391
 
2392
			#設置執行錯誤訊息
2393
			$result["error"]="函數".$result["function"]."需要參數";
2394
 
2395
			#回傳結果
2396
			return $result;
2397
 
2398
			}#if end
2399
 
2400
		#取得參數
2401
		$result["argu"]=$conf;
2402
 
2403
		#如果 $conf 不為陣列
2404
		if(gettype($conf)!=="array"){
2405
 
2406
			#設置執行失敗
2407
			$result["status"]="false";
2408
 
2409
			#設置執行錯誤訊息
2410
			$result["error"][]="\$conf變數須為陣列形態";
2411
 
2412
			#如果傳入的參數為 null
2413
			if(is_null($conf)){
2414
 
2415
				#設置執行錯誤訊息
2416
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
2417
 
2418
				}#if end
2419
 
2420
			#回傳結果
2421
			return $result;
2422
 
2423
			}#if end
226 liveuser 2424
 
48 liveuser 2425
		#檢查參數
2426
		#函式說明:
2427
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
2428
		#回傳結果:
2429
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2430
		#$result["error"],執行不正常結束的錯訊息陣列.
2431
		#$result["simpleError"],簡單表示的錯誤訊息.
2432
		#$result["function"],當前執行的函式名稱.
2433
		#$result["argu"],設置給予的參數.
2434
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
2435
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
2436
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
2437
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
2438
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
2439
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
2440
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
2441
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
2442
		#必填參數:
2443
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
2444
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
2445
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
2446
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
2447
		#可省略參數:
2448
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
2449
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("username","password","receiverMail","subject","plainBody","htmlBody","mailServer");
2450
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null、any代表不指定變數形態.其中 resource也包含"resource (closed)".
2451
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","array","string","string","string","string");
2452
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
2453
		#$conf["canBeEmptyString"]="false";
2454
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
2455
		#$conf["canNotBeEmpty"]=array();
2456
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
2457
		#$conf["canBeEmpty"]=array();
2458
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
2459
		#$conf["skipableVariableCanNotBeEmpty"]=array();
2460
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
237 liveuser 2461
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("mailerMailDisplay","mailerNameDisplay","receiverNameDisplay","attachment","attachmentName","attachmentMimeType","mailServerPort","userAgent","org","notifyReceived","signWithGPGid","signGpgThroughSocket","gpgPrivateKeyUser");
48 liveuser 2462
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
237 liveuser 2463
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","array","array","array","array","integer","string","string","string","string","string","string");
48 liveuser 2464
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
237 liveuser 2465
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("\$conf[\"username\"]","\$conf[\"username\"]",array(),null,null,null,465,"Powerd by QBPWCF(https://lib.qbpwcf.org)",null,"true",null,"false",null);
48 liveuser 2466
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
2467
		$conf["variableCheck::checkArguments"]["disallowAllSkipableVarIsEmpty"]="false";
2468
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
2469
		$conf["variableCheck::checkArguments"]["disallowAllSkipableVarIsEmptyArray"]="false";
2470
		#$conf["disallowAllSkipableVarNotExist"],字串,是否不允許每個可省略參數都不存在,預設為"false"代表允許,反之為"true".
2471
		$conf["variableCheck::checkArguments"]["disallowAllSkipableVarNotExist"]="true";
2472
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
2473
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("receiverMailDisplay","receiverNameDisplay");
2474
		#參考資料:
2475
		#array_keys=>http://php.net/manual/en/function.array-keys.php
2476
		#備註:
2477
		#無.
2478
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
2479
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 2480
 
48 liveuser 2481
		#如果檢查失敗
2482
		if($checkArguments["status"]==="false"){
226 liveuser 2483
 
48 liveuser 2484
			#設置錯誤識別
2485
			$result["status"]="false";
226 liveuser 2486
 
48 liveuser 2487
			#設置錯誤訊息
2488
			$result["error"]=$checkArguments;
226 liveuser 2489
 
48 liveuser 2490
			#回傳結果
2491
			return $result;
226 liveuser 2492
 
48 liveuser 2493
			}#if end
226 liveuser 2494
 
48 liveuser 2495
		#如果檢查不通過
2496
		if($checkArguments["passed"]==="false"){
226 liveuser 2497
 
48 liveuser 2498
			#設置錯誤識別
2499
			$result["status"]="false";
226 liveuser 2500
 
48 liveuser 2501
			#設置錯誤訊息
2502
			$result["error"]=$checkArguments;
226 liveuser 2503
 
48 liveuser 2504
			#回傳結果
2505
			return $result;
226 liveuser 2506
 
48 liveuser 2507
			}#if end
226 liveuser 2508
 
48 liveuser 2509
		#設置pear套件Net SMTP的位置
2510
		$locationOfPearNetSmtp="/usr/share/pear/Net/SMTP.php";
226 liveuser 2511
 
48 liveuser 2512
		#檢查需要的pear套件是否存在
2513
		#函式說明:
2514
		#檢查多個檔案與資料夾是否存在.
2515
		#回傳的結果:
2516
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
2517
		#$result["error"],錯誤訊息陣列.
2518
		#$resutl["function"],當前執行的涵式名稱.
2519
		#$result["argu"],使用的參數.
2520
		#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
2521
		#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
2522
		#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.
2523
		#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址,若"web"參數為"true",才會有該內容.
2524
		#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
2525
		#必填參數:
2526
		#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
2527
		$conf["filAccess::checkMultiFileExist"]["fileArray"]=array($locationOfPearNetSmtp);
2528
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
2529
		$conf["filAccess::checkMultiFileExist"]["fileArgu"]=__FILE__;
2530
		#可省略參數:
2531
		#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
2532
		$conf["filAccess::checkMultiFileExist"]["disableWebSearch"]="true";
2533
		#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
2534
		$conf["filAccess::checkMultiFileExist"]["userDir"]="false";
2535
		#$conf["web"],字串,檔案是放在web就是"true",反之為檔案系統"false",預設為"true".
2536
		$conf["filAccess::checkMultiFileExist"]["web"]="false";
2537
		#參考資料:
2538
		#http://php.net/manual/en/function.file-exists.php
2539
		#http://php.net/manual/en/control-structures.foreach.php
2540
		#備註:
2541
		#函數file_exists檢查的路徑為檔案系統的路徑
2542
		#$result["varName"][$i]結果未實作
2543
		$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["filAccess::checkMultiFileExist"]);
2544
		unset($conf["filAccess::checkMultiFileExist"]);
226 liveuser 2545
 
48 liveuser 2546
		#如果檢查失敗
2547
		if($checkMultiFileExist["status"]==="false"){
226 liveuser 2548
 
48 liveuser 2549
			#設置錯誤識別
2550
			$result["status"]="false";
226 liveuser 2551
 
48 liveuser 2552
			#設置錯誤訊息
2553
			$result["error"]=$checkMultiFileExist;
226 liveuser 2554
 
48 liveuser 2555
			#回傳結果
2556
			return $result;
226 liveuser 2557
 
48 liveuser 2558
			}#if end
226 liveuser 2559
 
58 liveuser 2560
		#如果不存在
48 liveuser 2561
		if($checkMultiFileExist["allExist"]==="false"){
226 liveuser 2562
 
48 liveuser 2563
			#設置錯誤識別
2564
			$result["status"]="false";
226 liveuser 2565
 
48 liveuser 2566
			#設置錯誤訊息
2567
			$result["error"][]=$checkMultiFileExist;
226 liveuser 2568
 
48 liveuser 2569
			#設置錯誤訊息
2570
			$result["error"][]="請確認 ".$locationOfPearNetSmtp." 可被存取";
226 liveuser 2571
 
48 liveuser 2572
			#回傳結果
2573
			return $result;
226 liveuser 2574
 
48 liveuser 2575
			}#if end
226 liveuser 2576
 
48 liveuser 2577
		#匯入需要的pear套件
226 liveuser 2578
		require_once($locationOfPearNetSmtp);
2579
 
48 liveuser 2580
		#create smtp object
2581
		$smtp = new \Net_SMTP($conf["mailServer"], $conf["mailServerPort"]);
226 liveuser 2582
 
48 liveuser 2583
		#如果有錯誤
2584
		if(\PEAR::isError($error = $smtp->connect())){
226 liveuser 2585
 
48 liveuser 2586
			#設置錯誤識別
2587
			$result["status"]="false";
226 liveuser 2588
 
48 liveuser 2589
			#設置錯誤訊息
2590
			$result["error"]=$error->getMessage();
226 liveuser 2591
 
48 liveuser 2592
			#回傳結果
2593
			return $result;
226 liveuser 2594
 
48 liveuser 2595
			}#if end
226 liveuser 2596
 
48 liveuser 2597
		#嘗試進行登入認證,方式目前都用"PLAIN"
2598
		$smtp->auth($conf["username"],$conf["password"],"PLAIN");
226 liveuser 2599
 
48 liveuser 2600
		# smtp command "MAIL FROM:"
2601
		$smtp->mailFrom($conf["mailerNameDisplay"]." <".$conf["mailerMailDisplay"].">");
226 liveuser 2602
 
48 liveuser 2603
		#初始化儲存 email head 的變數
2604
		$head="";
226 liveuser 2605
 
237 liveuser 2606
		#初始化儲存 email body 的變數
2607
		$body="";
226 liveuser 2608
 
48 liveuser 2609
		#設置收件人
2610
		foreach($conf["receiverMail"] as $index => $receiverMail){
226 liveuser 2611
 
48 liveuser 2612
			#若無顯示名稱參數
2613
			if(!isset($conf["receiverNameDisplay"][$index])){
226 liveuser 2614
 
48 liveuser 2615
				#若無顯示名稱參數,則預設採email來顯示.
2616
				$conf["receiverNameDisplay"][$index]=$receiverMail;
226 liveuser 2617
 
48 liveuser 2618
				}#if end
226 liveuser 2619
 
48 liveuser 2620
			#設置收件人的email與顯示名稱
2621
			$receiverMail=$conf["receiverNameDisplay"][$index]." <".$receiverMail.">";
226 liveuser 2622
 
48 liveuser 2623
			#設置To:資訊
2624
			$head=$head."To: ".$receiverMail."\r\n";
226 liveuser 2625
 
48 liveuser 2626
			#如果新增收件人失敗
2627
			if(\PEAR::isError($res=$smtp->rcptTo($receiverMail))){
226 liveuser 2628
 
48 liveuser 2629
				#設置錯誤識別
2630
				$result["status"]="false";
226 liveuser 2631
 
48 liveuser 2632
				#設置錯誤訊息
2633
				$result["error"]="Unable to add recipient <".$receiverMail.">: ".$res->getMessage();
226 liveuser 2634
 
48 liveuser 2635
				#回傳結果
2636
				return $result;
226 liveuser 2637
 
48 liveuser 2638
				}#if end
226 liveuser 2639
 
48 liveuser 2640
			}#foreach end
226 liveuser 2641
 
48 liveuser 2642
		#設置sender資訊
2643
		$head=$head."From: ".$conf["mailerNameDisplay"]." <".$conf["mailerMailDisplay"].">"."\r\n";
226 liveuser 2644
 
48 liveuser 2645
		#設置Replay-to資訊
2646
		$head=$head."Reply-To: ".$conf["mailerNameDisplay"]." <".$conf["mailerMailDisplay"].">"."\r\n";
226 liveuser 2647
 
48 liveuser 2648
		#如果有設置回報已讀通知
2649
		if($conf["notifyReceived"]==="true"){
226 liveuser 2650
 
48 liveuser 2651
			#Disposition-Notification-To: liveuser@qbpwcf.org
2652
			$head=$head."Disposition-Notification-To: ".$conf["mailerMailDisplay"]."\r\n";
226 liveuser 2653
 
48 liveuser 2654
			}#if end
226 liveuser 2655
 
48 liveuser 2656
		#建立body中的Subject
2657
		$head=$head."Subject: ".$conf["subject"]."\r\n";
226 liveuser 2658
 
48 liveuser 2659
		#函式說明:
2660
		#使用 linux 的 uuid 指令來產生 uuid 字串
2661
		#回傳結果:
2662
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2663
		#$result["error"],錯誤訊息.
2664
		#$result["function"],當前執行的函式名稱.
2665
		#$result["content"],uuid.
2666
		#必填參數:
2667
		#無.
2668
		#可省略參數:
2669
		#無.
2670
		#參考資料:
2671
		#無.
2672
		#備註:
2673
		#無.
2674
		$uuid=cmd::uuid();
226 liveuser 2675
 
48 liveuser 2676
		#如果取得uuid失敗
2677
		if($uuid["status"]==="false"){
226 liveuser 2678
 
48 liveuser 2679
			#設置錯誤識別
2680
			$result["status"]="false";
226 liveuser 2681
 
48 liveuser 2682
			#設置錯誤訊息
2683
			$result["error"][]="Unable to create Message-ID";
226 liveuser 2684
 
48 liveuser 2685
			#設置錯誤訊息
2686
			$result["error"][]=$uuid;
226 liveuser 2687
 
48 liveuser 2688
			#回傳結果
2689
			return $result;
226 liveuser 2690
 
48 liveuser 2691
			}#if end
226 liveuser 2692
 
48 liveuser 2693
		#函式說明:
2694
		#將字串特定關鍵字與其前面的內容剔除
2695
		#回傳結果:
2696
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2697
		#$result["error"],錯誤訊息陣列.
2698
		#$result["warning"],警告訊息鎮列.
2699
		#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
2700
		#$result["function"],當前執行的函數名稱.
2701
		#$result["argu"],使用的參數.
2702
		#$result["oriStr"],要處理的原始字串內容.
2703
		#$result["content"],處理好的的字串內容.
2704
		#$result["deleted"],被移除的內容.
2705
		#必填參數:
2706
		#$conf["stringIn"],字串,要處理的字串.
2707
		$conf["stringProcess::delStrBeforeKeyWord"]["stringIn"]=$conf["mailServer"];
2708
		#$conf["keyWord"],字串,特定字串.
2709
		$conf["stringProcess::delStrBeforeKeyWord"]["keyWord"]="//";
2710
		#可省略參數:
2711
		#$conf["recursive"],字串,預設為"false"代表找到一個關鍵字就會停止;"true"代表會即重複執行,知道沒有關鍵字為止.
2712
		$conf["stringProcess::delStrBeforeKeyWord"]["recursive"]="true";
2713
		#$conf["lastResult"],陣列,本函式前次執行的結果,若沒有找到關鍵字,則會改回傳該內容.
2714
		#$conf["lastResult"]=$delStrBeforeKeyWord;
2715
		#參考資料:
2716
		#無.
2717
		#備註:
2718
		#無.
2719
		$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf["stringProcess::delStrBeforeKeyWord"]);
2720
		unset($conf["stringProcess::delStrBeforeKeyWord"]);
226 liveuser 2721
 
48 liveuser 2722
		#如果取得Message-ID的domain失敗
2723
		if($delStrBeforeKeyWord["status"]==="false"){
226 liveuser 2724
 
48 liveuser 2725
			#設置錯誤識別
2726
			$result["status"]="false";
226 liveuser 2727
 
48 liveuser 2728
			#設置錯誤訊息
2729
			$result["error"][]="Unable to create domain of Message-ID";
226 liveuser 2730
 
48 liveuser 2731
			#設置錯誤訊息
2732
			$result["error"][]=$delStrBeforeKeyWord;
226 liveuser 2733
 
48 liveuser 2734
			#回傳結果
2735
			return $result;
226 liveuser 2736
 
48 liveuser 2737
			}#if end
226 liveuser 2738
 
48 liveuser 2739
		#取得Message-ID對應的domain
2740
		$MessageIdDomain=$delStrBeforeKeyWord["content"];
226 liveuser 2741
 
48 liveuser 2742
		#建立Message-ID
2743
		$head=$head."Message-ID: <".$uuid["content"]."@".$MessageIdDomain.">"."\r\n";;
226 liveuser 2744
 
237 liveuser 2745
		#設置 MIME Version
2746
		$head=$head."MIME-Version: 1.0\r\n";
2747
 
48 liveuser 2748
		#設置User-Agent
2749
		$head=$head."User-Agent: ".$conf["userAgent"]."\r\n";
226 liveuser 2750
 
2751
		#設置Date:
48 liveuser 2752
		$head=$head."Date: ".gmdate("Y-m-d H:i:s")."\r\n";
226 liveuser 2753
 
48 liveuser 2754
		#如果有設置 org
2755
		if(isset($conf["org"])){
226 liveuser 2756
 
48 liveuser 2757
			#設置 Organization
2758
			$head=$head."Organization: ".$conf["org"]."\r\n";
226 liveuser 2759
 
48 liveuser 2760
			}#if end
226 liveuser 2761
 
48 liveuser 2762
		#函式說明:
2763
		#建立以圖片(PNG格式)呈現的驗證碼.
2764
		#回傳的解果:
2765
		#$result["status"],執行是否正常,"true"代表執行成功,"false"代表執行失敗.
2766
		#$result["error"],錯誤訊息.
2767
		#$result["function"],檔前執行的函數名稱.
2768
		#$result["randNumberWord"],傳驗證碼的內容.
2769
		#$result["imgAddress"],包含src圖片的位置與名稱.
2770
		#$result["imgSrcVal"],放在src裏面的圖片位置與名稱.
2771
		#必填參數:
2772
		#$conf["imgAddressAndName"],字串,爲驗證碼圖片儲存的位置與名稱,副檔名程式會自動產生
2773
		$conf["authenticate::validationCode"]["imgAddressAndName"]="/tmp/xxx.png";
2774
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
2775
		$conf["authenticate::validationCode"]["fileArgu"]=__FILE__;
2776
		#可省略參數:
2777
		#$conf["num"],字串,爲驗證碼的位數,請輸入阿拉伯數字,預設為"8"位數.
2778
		#$conf["num"]="8";
2779
		#$conf["disableImg"],字串,是否要取消驗證碼圖片的輸出,"true"為要取消,預設為"false"為不取消
2780
		$conf["authenticate::validationCode"]["disableImg"]="true";
2781
		#$conf["imgToData"],字串,預設為"true"代表將圖片轉存成base64圖片,並將原始圖片移除;反之為"false"
2782
		#$conf["imgToData"]="true";
2783
		#$conf["class"],字串,圖片要套用的css樣式類別.
2784
		#$conf["class"]="";
2785
		#$conf["content"],字串陣列,允許的亂數陣列內容,預設爲(1~9 and A~Z).
2786
		#$conf["content"]=array();
2787
		#參考資料:
2788
		#無.
2789
		#備註:
2790
		#無.
2791
		$validationCode=authenticate::validationCode($conf["authenticate::validationCode"]);
2792
		unset($conf["authenticate::validationCode"]);
226 liveuser 2793
 
48 liveuser 2794
		#如果檢查失敗
2795
		if($validationCode["status"]==="false"){
226 liveuser 2796
 
48 liveuser 2797
			#設置錯誤識別
2798
			$result["status"]="false";
226 liveuser 2799
 
48 liveuser 2800
			#設置錯誤訊息
2801
			$result["error"]=$validationCode;
226 liveuser 2802
 
48 liveuser 2803
			#回傳結果
2804
			return $result;
226 liveuser 2805
 
48 liveuser 2806
			}#if end
226 liveuser 2807
 
48 liveuser 2808
		#初始化 boundary
237 liveuser 2809
		$mixBoundary=$validationCode["randNumberWord"];
226 liveuser 2810
 
48 liveuser 2811
		#初始化 boundary start
237 liveuser 2812
		$mixBoundaryS="--".$mixBoundary;
226 liveuser 2813
 
48 liveuser 2814
		#初始化 boundary end
237 liveuser 2815
		$mixBoundaryE=$mixBoundaryS."--";
226 liveuser 2816
 
237 liveuser 2817
		#函式說明:
2818
		#建立以圖片(PNG格式)呈現的驗證碼.
2819
		#回傳的解果:
2820
		#$result["status"],執行是否正常,"true"代表執行成功,"false"代表執行失敗.
2821
		#$result["error"],錯誤訊息.
2822
		#$result["function"],檔前執行的函數名稱.
2823
		#$result["randNumberWord"],傳驗證碼的內容.
2824
		#$result["imgAddress"],包含src圖片的位置與名稱.
2825
		#$result["imgSrcVal"],放在src裏面的圖片位置與名稱.
2826
		#必填參數:
2827
		#$conf["imgAddressAndName"],字串,爲驗證碼圖片儲存的位置與名稱,副檔名程式會自動產生
2828
		$conf["authenticate::validationCode"]["imgAddressAndName"]="/tmp/xxx.png";
2829
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
2830
		$conf["authenticate::validationCode"]["fileArgu"]=__FILE__;
2831
		#可省略參數:
2832
		#$conf["num"],字串,爲驗證碼的位數,請輸入阿拉伯數字,預設為"8"位數.
2833
		#$conf["num"]="8";
2834
		#$conf["disableImg"],字串,是否要取消驗證碼圖片的輸出,"true"為要取消,預設為"false"為不取消
2835
		$conf["authenticate::validationCode"]["disableImg"]="true";
2836
		#$conf["imgToData"],字串,預設為"true"代表將圖片轉存成base64圖片,並將原始圖片移除;反之為"false"
2837
		#$conf["imgToData"]="true";
2838
		#$conf["class"],字串,圖片要套用的css樣式類別.
2839
		#$conf["class"]="";
2840
		#$conf["content"],字串陣列,允許的亂數陣列內容,預設爲(1~9 and A~Z).
2841
		#$conf["content"]=array();
2842
		#參考資料:
2843
		#無.
2844
		#備註:
2845
		#無.
2846
		$validationCode=authenticate::validationCode($conf["authenticate::validationCode"]);
2847
		unset($conf["authenticate::validationCode"]);
2848
 
2849
		#如果檢查失敗
2850
		if($validationCode["status"]==="false"){
2851
 
2852
			#設置錯誤識別
2853
			$result["status"]="false";
2854
 
2855
			#設置錯誤訊息
2856
			$result["error"]=$validationCode;
2857
 
2858
			#回傳結果
2859
			return $result;
2860
 
2861
			}#if end
2862
 
2863
		#初始化 boundary
2864
		$altBoundary=$validationCode["randNumberWord"];
2865
 
2866
		#初始化 boundary start
2867
		$altBoundaryS="--".$altBoundary;
2868
 
2869
		#初始化 boundary end
2870
		$altBoundaryE=$altBoundaryS."--";
2871
 
48 liveuser 2872
		#取得放置於head的Contet-Type描述
237 liveuser 2873
		$contentDescInHead="Content-Type: multipart/alternative; boundary=\"".$altBoundary."\"\r\n\r\n";
226 liveuser 2874
 
237 liveuser 2875
		#設置目前的 type 為alt,代表只有 text 跟 html
2876
		$contentDescInHeadType="alt";
2877
 
48 liveuser 2878
		#設置信件本文(純文字與html兩種)
237 liveuser 2879
		$body=$body.$altBoundaryS."\r\n";
2880
		$body=$body."Content-Type: text/plain; charset=UTF-8\r\n";
2881
		$body=$body."\r\n";
2882
		$body=$body.$conf["plainBody"]."\r\n";
2883
		$body=$body."\r\n";
2884
		$body=$body.$altBoundaryS."\r\n";
2885
		$body=$body."Content-Type: text/html; charset=UTF-8\r\n";
2886
		$body=$body."\r\n";
2887
		$body=$body.$conf["htmlBody"]."\r\n";
2888
		$body=$body."\r\n";
239 liveuser 2889
 
237 liveuser 2890
		#如果沒有附件
2891
		if(!isset($conf["attachment"])){
239 liveuser 2892
 
2893
			#alt Boundary end
237 liveuser 2894
			$body=$body.$altBoundaryE."\r\n";
239 liveuser 2895
 
237 liveuser 2896
			}#if end
239 liveuser 2897
 
48 liveuser 2898
		#如果有設定要上傳附件
237 liveuser 2899
		else{
226 liveuser 2900
 
237 liveuser 2901
			#將原本放置於head的alt Contet-Type描述,變成body的內容,串在 body 前面.
2902
			$body=$contentDescInHead.$body;
2903
 
2904
			#更新放置於head的Contet-Type描述
2905
			$contentDescInHead="Content-Type: multipart/mixed; boundary=".$mixBoundary."\r\n\r\n";
2906
 
2907
			#設置目前的 type 為 mix,代表有 text 跟 html 以及 attachment
2908
			$contentDescInHeadType="mix";
239 liveuser 2909
 
237 liveuser 2910
			#設置 mix boundary start,串在 body 其面.
2911
			$body=$mixBoundaryS."\r\n".$body;
2912
 
48 liveuser 2913
			#依據每個附件
2914
			for($i=0;$i<count($conf["attachment"]);$i++){
226 liveuser 2915
 
48 liveuser 2916
				#初始化寄送附件的語法
2917
				$attachment="";
226 liveuser 2918
 
48 liveuser 2919
				#確認目標檔案是否存在
2920
				#函式說明:檢查多個檔案是否存在
2921
				#回傳的結果:
2922
				#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
2923
				#$result["error"],錯誤訊息陣列.
2924
				#$resutl["function"],當前執行的涵式名稱.
2925
				#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
2926
				#$result["varName"][$i],爲第$i個資料夾或檔案的名稱。
2927
				#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
2928
				#必填參數:
237 liveuser 2929
				$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=__FILE__;
48 liveuser 2930
				$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($conf["attachment"][$i]);#要檢查書否存在的檔案有哪些,須爲一維陣列數值。
2931
				#參考資料來源:
2932
				#http://php.net/manual/en/function.file-exists.php
2933
				#http://php.net/manual/en/control-structures.foreach.php
2934
				$checkMutiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
2935
				unset($conf["fileAccess::checkMultiFileExist"]);
226 liveuser 2936
 
237 liveuser 2937
				#debug
2938
				#var_dump(__LINE__,$checkMutiFileExist);exit;
239 liveuser 2939
 
48 liveuser 2940
				#如果檢查失敗
237 liveuser 2941
				if($checkMutiFileExist["status"]==="false"){
226 liveuser 2942
 
48 liveuser 2943
					#設置錯誤識別
2944
					$result["status"]="false";
2945
 
2946
					#設置錯誤資訊
2947
					$result["error"]=$checkMutiFileExist;
2948
 
2949
					#回傳結果
2950
					return $result;
226 liveuser 2951
 
48 liveuser 2952
					}#if end
226 liveuser 2953
 
48 liveuser 2954
				#如果檔案不存在
2955
				if($checkMutiFileExist["varExist"][0]=="false"){
226 liveuser 2956
 
48 liveuser 2957
					#設置錯誤識別
2958
					$result["status"]="false";
2959
 
2960
					#設置錯誤資訊
2961
					$result["error"]=$checkMutiFileExist;
2962
 
2963
					#回傳結果
2964
					return $result;
226 liveuser 2965
 
48 liveuser 2966
					}#if end
226 liveuser 2967
 
237 liveuser 2968
				#取得附件的絕對位置
2969
				$attachAddr=$checkMutiFileExist["varNameFullPath"][0];
239 liveuser 2970
 
237 liveuser 2971
				#函式說明:
2972
				#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
2973
				#回傳的變數說明:
2974
				#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
2975
				#$result["error"],錯誤訊息提示.
2976
				#$result["warning"],警告訊息.
2977
				#$result["function"],當前執行的函數名稱.
2978
				#$result["fileContent"],爲檔案的內容陣列.
2979
				#$result["lineCount"],爲檔案內容總共的行數.
2980
				#$result["fullContent"],為檔案的完整內容.
2981
				#$result["base64dataOnly"],檔案的base64data.
2982
				#$result["base64data"],為在網頁上給予src參數的數值.
2983
				#$result["mimeType"],為檔案的mime type.
2984
				#必填參數:
2985
				#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
2986
				$conf["fileAccess::getFileContent"]["filePositionAndName"]=$attachAddr;
2987
				#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
2988
				$conf["fileAccess::getFileContent"]["fileArgu"]=__FILE__;
2989
				#可省略參數:
2990
				#$conf["web"],是要取得網路上的檔案則為"true";反之預設為"false".
2991
				#$conf["web"]="true";
2992
				#$conf["createIfnotExist"],字串,預設為"false"代表檔案不存在也不需要建立;反之為"true".
2993
				#$conf["createIfnotExist"]="false";
2994
				#$conf["autoDeleteSpaceOnEachLineStart"],字串,預設為"false",不做額外處理;反之為"true"
2995
				#$conf["autoDeleteSpaceOnEachLineStart"]="false";
2996
				#參考資料:
2997
				#file(),取得檔案內容的行數.
2998
				#file=>http:#php.net/manual/en/function.file.php
2999
				#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
3000
				#filesize=>http://php.net/manual/en/function.filesize.php
3001
				#參考資料:
3002
				#無.
3003
				#備註:
3004
				#無.
3005
				$getFileContent=fileAccess::getFileContent($conf["fileAccess::getFileContent"]);
3006
				unset($conf["fileAccess::getFileContent"]);
239 liveuser 3007
 
237 liveuser 3008
				#如果解析檔案資訊失敗
3009
				if($getFileContent["status"]==="false"){
226 liveuser 3010
 
237 liveuser 3011
					#設置錯誤識別
3012
					$result["status"]="false";
226 liveuser 3013
 
237 liveuser 3014
					#設置錯誤資訊
3015
					$result["error"]=$getFileContent;
3016
 
3017
					#回傳結果
3018
					return $result;
3019
 
48 liveuser 3020
					}#if end
239 liveuser 3021
 
237 liveuser 3022
				#取得檔案的 base64 內容
3023
				$attachmentB64=$getFileContent["base64dataOnly"];
239 liveuser 3024
 
237 liveuser 3025
				#取得自動判斷的 mime type
3026
				$attachmentAutoDetectedMimeType=$getFileContent["mimeType"];
226 liveuser 3027
 
48 liveuser 3028
				#如果 $conf["attachmentName"] 不存在
3029
				if(!isset($conf["attachmentName"])){
226 liveuser 3030
 
48 liveuser 3031
					#涵是說明:
3032
					#取得檔案路徑字串的路徑與檔案的名稱與檔案副檔名
3033
					#回傳的結果:
3034
					#$result["status"],執行是否正常,"true"正常,"false"代表不正常.
3035
					#$result["error"],錯誤訊息.
3036
					#$result["function"],當前執行的函式名稱.
3037
					#$result["filePath"],路徑字串.
3038
					#$result["fileName"],檔案名稱字串.
3039
					#$result["fileExtention"],檔案的副檔名.
3040
					#$result["fullFileName"],含副檔名的檔案名稱.
3041
					#$result["fullFilePathAndName"],完整的檔案路徑(含副檔名).
3042
					#必填參數:
3043
					#$conf["fileAddressAndName"],字串,檔案名稱與其路徑.
3044
					$conf["fileAccess::getFileAddressAndNameAndFileExtention"]["fileAddressAndName"]=$conf["attachment"][$i];
3045
					#可省略的參數:
3046
					#無.
3047
					$getFileAddressAndNameAndFileExtention=fileAccess::getFileAddressAndNameAndFileExtention($conf["fileAccess::getFileAddressAndNameAndFileExtention"]);
3048
					unset($conf["fileAccess::getFileAddressAndNameAndFileExtention"]);
226 liveuser 3049
 
48 liveuser 3050
					#如果解析檔案資訊失敗
3051
					if($getFileAddressAndNameAndFileExtention["status"]==="false"){
226 liveuser 3052
 
48 liveuser 3053
						#設置錯誤識別
3054
						$result["status"]="false";
3055
 
3056
						#設置錯誤資訊
3057
						$result["error"]=$getFileAddressAndNameAndFileExtention;
3058
 
3059
						#回傳結果
3060
						return $result;
226 liveuser 3061
 
48 liveuser 3062
						}#if end
226 liveuser 3063
 
48 liveuser 3064
					#設定附件名稱
3065
					$conf["attachmentName"][$i]=$getFileAddressAndNameAndFileExtention["fullFileName"];
226 liveuser 3066
 
48 liveuser 3067
					}#if end
226 liveuser 3068
 
48 liveuser 3069
				#反之如果 $conf["attachmentName"][$i] 不存在
3070
				else if(!isset($conf["attachmentName"][$i])){
226 liveuser 3071
 
48 liveuser 3072
					#涵是說明:
3073
					#取得檔案路徑字串的路徑與檔案的名稱與檔案副檔名
3074
					#回傳的結果:
3075
					#$result["status"],執行是否正常,"true"正常,"false"代表不正常.
3076
					#$result["error"],錯誤訊息.
3077
					#$result["function"],當前執行的函式名稱.
3078
					#$result["filePath"],路徑字串.
3079
					#$result["fileName"],檔案名稱字串.
3080
					#$result["fileExtention"],檔案的副檔名.
3081
					#$result["fullFileName"],含副檔名的檔案名稱.
3082
					#$result["fullFilePathAndName"],完整的檔案路徑(含副檔名).
3083
					#必填參數:
3084
					#$conf["fileAddressAndName"],字串,檔案名稱與其路徑.
3085
					$conf["fileAccess::getFileAddressAndNameAndFileExtention"]["fileAddressAndName"]=$conf["attachment"][$i];
3086
					#可省略的參數:
3087
					#無.
3088
					$getFileAddressAndNameAndFileExtention=fileAccess::getFileAddressAndNameAndFileExtention($conf["fileAccess::getFileAddressAndNameAndFileExtention"]);
3089
					unset($conf["fileAccess::getFileAddressAndNameAndFileExtention"]);
226 liveuser 3090
 
48 liveuser 3091
					#如果解析檔案資訊失敗
237 liveuser 3092
					if($getFileAddressAndNameAndFileExtention["status"]==="false"){
226 liveuser 3093
 
48 liveuser 3094
						#設置錯誤識別
3095
						$result["status"]="false";
3096
 
3097
						#設置錯誤資訊
3098
						$result["error"]=$getFileAddressAndNameAndFileExtention;
3099
 
3100
						#回傳結果
3101
						return $result;
226 liveuser 3102
 
48 liveuser 3103
						}#if end
226 liveuser 3104
 
48 liveuser 3105
					#設定附件名稱
3106
					$conf["attachmentName"][$i]=$getFileAddressAndNameAndFileExtention["fullFileName"];
226 liveuser 3107
 
48 liveuser 3108
					}#if end
226 liveuser 3109
 
48 liveuser 3110
				#如果 $conf["attachmentMimeType"] 不存在
3111
				if(!isset($conf["attachmentMimeType"])){
226 liveuser 3112
 
48 liveuser 3113
					#設定檔案類型
237 liveuser 3114
					$conf["attachmentMimeType"][$i]=$attachmentAutoDetectedMimeType;
226 liveuser 3115
 
48 liveuser 3116
					}#if end
226 liveuser 3117
 
3118
				#反之如果 $conf["attachmentMimeType"][$i] 不存在
237 liveuser 3119
				else if(!isset($conf["attachmentMimeType"][$i])){
226 liveuser 3120
 
237 liveuser 3121
					$conf["attachmentMimeType"][$i]=$attachmentAutoDetectedMimeType;
226 liveuser 3122
 
48 liveuser 3123
					}#if end
226 liveuser 3124
 
237 liveuser 3125
				#debug
3126
				#var_dump(__LINE__,$attachAddr,$conf["attachmentMimeType"],$conf["attachmentName"][$i]);
3127
 
48 liveuser 3128
				#加上寄送附件的語法
237 liveuser 3129
				$attachment=$attachment.$mixBoundaryS."\r\n";
48 liveuser 3130
				$attachment=$attachment."Content-Type: ".$conf["attachmentMimeType"][$i]."; name=".$conf["attachmentName"][$i]."\r\n";
3131
				$attachment=$attachment."Content-Disposition: attachment; filename=".$conf["attachmentName"][$i]."\r\n";
226 liveuser 3132
				$attachment=$attachment."Content-Transfer-Encoding: base64\r\n";
48 liveuser 3133
				$attachment=$attachment."X-Attachment-Id: f_io1ikfii".$i."\r\n";
239 liveuser 3134
 
48 liveuser 3135
				#斷行後附加檔案字串
237 liveuser 3136
				$attachment=$attachment."\r\n".$attachmentB64."\r\n";
226 liveuser 3137
 
48 liveuser 3138
				#如果是最後一個附件
3139
				if($i===count($conf["attachment"])-1){
226 liveuser 3140
 
48 liveuser 3141
					#混合資料結尾
237 liveuser 3142
					#$attachment=$attachment.$mixBoundary."\r\n";
226 liveuser 3143
 
48 liveuser 3144
					}#if end
226 liveuser 3145
 
48 liveuser 3146
				#增加到信件內文的結尾
237 liveuser 3147
				$body=$body.$attachment;
226 liveuser 3148
 
48 liveuser 3149
				}#for end
239 liveuser 3150
 
237 liveuser 3151
			#加上 mix Boundary end
3152
			$body=$body."\r\n".$mixBoundaryE."\r\n\r\n";
239 liveuser 3153
 
237 liveuser 3154
			}#else end
226 liveuser 3155
 
48 liveuser 3156
		#body end
226 liveuser 3157
 
48 liveuser 3158
		#如果有指定 signWithGPGid
3159
		if(isset($conf["signWithGPGid"])){
226 liveuser 3160
 
48 liveuser 3161
			#將原本的 Content-Type 放到 data 前面.
237 liveuser 3162
			$body=$contentDescInHead.$body;
226 liveuser 3163
 
58 liveuser 3164
			#sign之前的內容,要先符合每列不得大於70的字元的規定
237 liveuser 3165
			$body=wordwrap($body,70,"\r\n",true);
226 liveuser 3166
 
237 liveuser 3167
			#如果是要透過 qbpwcf-uscok 來進行
3168
			if($conf["signGpgThroughSocket"]==="true"){
239 liveuser 3169
 
237 liveuser 3170
				# 取得 username 參數 "@" 前面的內容
3171
				#函式說明:
3172
				#將字串特定關鍵字與其後面的內容剔除
3173
				#回傳結果:
3174
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3175
				#$result["error"],錯誤訊息陣列.
3176
				#$result["warning"],警告訊息鎮列.
3177
				#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
3178
				#$result["function"],當前執行的函數名稱.
3179
				#$result["oriStr"],要處理的原始字串內容.
3180
				#$result["content"],處理好的的字串內容.
3181
				#$result["deleted"],被移除的內容.
3182
				#$result["argu"],使用的參數.
3183
				#必填參數:
3184
				#$conf["stringIn"],字串,要處理的字串.
3185
				$conf["stringProcess::delStrAfterKeyWord"]["stringIn"]=$conf["username"];
3186
				#$conf["keyWord"],字串,特定字串.
3187
				$conf["stringProcess::delStrAfterKeyWord"]["keyWord"]="@";
3188
				#可省略參數:
3189
				#$conf["deleteLastRepeatedOne"],字串,預設為"false";若為"true"則代表連續遇到同 $conf["keyWord"] 的內容,要將移除內容的起點往後移動到為後一個 $conf["keyWord"].
3190
				#$conf["deleteLastRepeatedOne"]="";
3191
				#參考資料:
3192
				#無.
3193
				#備註:
3194
				#無.
3195
				$delStrAfterKeyWord=stringProcess::delStrAfterKeyWord($conf["stringProcess::delStrAfterKeyWord"]);
3196
				unset($conf["stringProcess::delStrAfterKeyWord"]);
239 liveuser 3197
 
237 liveuser 3198
				#如果執行失敗
3199
				if($delStrAfterKeyWord["status"]==="false"){
226 liveuser 3200
 
237 liveuser 3201
					#設置錯誤識別
3202
					$result["status"]="false";
226 liveuser 3203
 
237 liveuser 3204
					#設置錯誤資訊
3205
					$result["error"]=$delStrAfterKeyWord;
48 liveuser 3206
 
237 liveuser 3207
					#回傳結果
3208
					return $result;
48 liveuser 3209
 
237 liveuser 3210
					}#if end
239 liveuser 3211
 
237 liveuser 3212
				#預設的賬戶名稱
3213
				$user=$conf["username"];
239 liveuser 3214
 
237 liveuser 3215
				#如果含有 "@" 存在
3216
				if($delStrAfterKeyWord["founded"]==="true"){
226 liveuser 3217
 
237 liveuser 3218
					#取得賬戶名稱
3219
					$user=$delStrAfterKeyWord["content"];
239 liveuser 3220
 
237 liveuser 3221
					}#if end
239 liveuser 3222
 
48 liveuser 3223
				}#if end
239 liveuser 3224
 
237 liveuser 3225
			#debug
3226
			#var_dump(__LINE__,"data2sign",$body);
239 liveuser 3227
 
237 liveuser 3228
			#初始化要給 external::callShell 的 argu 參數內容
3229
			$arguForExternalCallShell=array(base64_encode($body),"|");
239 liveuser 3230
 
237 liveuser 3231
			#如果是要透過 qbpwcf-uscok 來進行
3232
			if($conf["signGpgThroughSocket"]==="true"){
239 liveuser 3233
 
237 liveuser 3234
				#如果有指定 gpgPrivateKeyUser 參數
3235
				if(isset($conf["gpgPrivateKeyUser"])){
239 liveuser 3236
 
237 liveuser 3237
					#加上使用 sudo 指令
3238
					$arguForExternalCallShell[]="sudo";
239 liveuser 3239
 
237 liveuser 3240
					#加上指定使用者的參數識別
3241
					$arguForExternalCallShell[]="-u";
239 liveuser 3242
 
237 liveuser 3243
					#加上指定使用者的參數數值
3244
					$arguForExternalCallShell[]=$conf["gpgPrivateKeyUser"];
239 liveuser 3245
 
237 liveuser 3246
					}#if end
239 liveuser 3247
 
237 liveuser 3248
				}#if end
239 liveuser 3249
 
237 liveuser 3250
			#使用 gpg 指令
3251
			$arguForExternalCallShell[]="gpg";
239 liveuser 3252
 
237 liveuser 3253
			#指定 id 的參數
3254
			$arguForExternalCallShell[]="-u";
226 liveuser 3255
 
237 liveuser 3256
			#指定 id
3257
			$arguForExternalCallShell[]=$conf["signWithGPGid"];
226 liveuser 3258
 
237 liveuser 3259
			#指定 要簽署 的參數
3260
			$arguForExternalCallShell[]="--armor";
48 liveuser 3261
 
237 liveuser 3262
			#指定要可以清楚識別的簽署方式
3263
			$arguForExternalCallShell[]="--detach-sign";
48 liveuser 3264
 
237 liveuser 3265
			#如果是要透過 qbpwcf-uscok 來進行
3266
			if($conf["signGpgThroughSocket"]==="true"){
239 liveuser 3267
 
237 liveuser 3268
				#函式說明:
3269
				#連線到 usr/bin/qbpwcf-usock.php 產生的  unix domain socket,運行指定的指令.
3270
				#回傳結果:
3271
				#$result["status"],"true"代表執行正常;"false"代表執行不正常.
3272
				#$result["error"],錯誤訊息陣列.
3273
				#$result["function"],當前執行的函式名稱.
3274
				#$result["argu"],使用的參數.
3275
				#$result["content"],執行完指令的結果,回傳的格式為external::callShell的回傳結果.
3276
				#必填參數:
3277
				#$conf["fileArgu"],字串,變數__FILE__的內容.
3278
				$conf["sock::execAnyCmdByQBPWCFunixSocket"]["fileArgu"]=__FILE__;
3279
				#$conf["command"],字串,要執行的指令名稱.
3280
				$conf["sock::execAnyCmdByQBPWCFunixSocket"]["command"]="base64decode.php";
3281
				#可省略參數:
3282
				#$conf["sock"],字串,要連線的 usr/bin/qbpwcf-sock.php(sock::unixDomainSockServer) 所產生的 unix domain socket 路徑與名稱,預設為 qbpwcf_usock_path.
3283
				#$conf["sock"]=qbpwcf_usock_path;
3284
				#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
3285
				$conf["sock::execAnyCmdByQBPWCFunixSocket"]["argu"]=$arguForExternalCallShell;
3286
				#$conf["commandIncludeArgu"],字串,是否command含有參數,預設為"false"代表沒有;反之為"true".
3287
				$conf["sock::execAnyCmdByQBPWCFunixSocket"]["commandIncludeArgu"]="false";
3288
				#$conf["commandInBg"],字串,是否要將程序放在背景執行,再取得相關資訊,預設為"false"代表不要;反之為"true".
3289
				#$conf["commandInBg"]="false";
3290
				#參考資料:
3291
				#無.
3292
				#備註:
3293
				#無.
3294
				$execAnyCmdByQBPWCFunixSocket=sock::execAnyCmdByQBPWCFunixSocket($conf["sock::execAnyCmdByQBPWCFunixSocket"]);
3295
				unset($conf["sock::execAnyCmdByQBPWCFunixSocket"]);
239 liveuser 3296
 
237 liveuser 3297
				#如果解析檔案資訊失敗
3298
				if($execAnyCmdByQBPWCFunixSocket["status"]==="false"){
226 liveuser 3299
 
237 liveuser 3300
					#設置錯誤識別
3301
					$result["status"]="false";
3302
 
3303
					#設置錯誤資訊
3304
					$result["error"]=$execAnyCmdByQBPWCFunixSocket;
3305
 
3306
					#回傳結果
3307
					return $result;
3308
 
3309
					}#if end
239 liveuser 3310
 
237 liveuser 3311
				#取得執行後的回傳結果
3312
				$callShell=$execAnyCmdByQBPWCFunixSocket["content"];
239 liveuser 3313
 
48 liveuser 3314
				}#if end
239 liveuser 3315
 
237 liveuser 3316
			#反之
3317
			else{
239 liveuser 3318
 
237 liveuser 3319
				#用gpg指令簽署body
3320
				#函式說明:
3321
				#呼叫shell執行系統命令,並取得回傳的內容.
3322
				#回傳結果:
3323
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3324
				#$result["error"],錯誤訊息陣列.
3325
				#$result["function"],當前執行的函數名稱.
3326
				#$result["argu"],使用的參數.
3327
				#$result["cmd"],執行的指令內容.
3328
				#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
3329
				#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
3330
				#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
3331
				#$result["running"],是否還在執行.
3332
				#$result["pid"],pid.
3333
				#$result["statusCode"],執行結束後的代碼.
3334
				#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
3335
				#必填參數:
3336
				#$conf["command"],字串,要執行的指令.
3337
				$conf["external::callShell"]["command"]="base64decode.php";
3338
				#$conf["fileArgu"],字串,變數__FILE__的內容.
3339
				$conf["external::callShell"]["fileArgu"]=__FILE__;
3340
				#可省略參數:
3341
				#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
3342
				$conf["external::callShell"]["argu"]=$arguForExternalCallShell;
3343
				#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
3344
				#$conf["arguIsAddr"]=array();
3345
				#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
3346
				#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
3347
				#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
3348
				#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
3349
				#$conf["enablePrintDescription"]="true";
3350
				#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
3351
				#$conf["printDescription"]="";
3352
				#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
3353
				$conf["external::callShell"]["escapeshellarg"]="false";
3354
				#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
3355
				#$conf["thereIsShellVar"]=array();
3356
				#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
3357
				#$conf["username"]="";
3358
				#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
3359
				#$conf["password"]="";
3360
				#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
3361
				#$conf["useScript"]="";
3362
				#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
3363
				#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
3364
				#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
3365
				#$conf["inBackGround"]="";
3366
				#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
3367
				#$conf["getErr"]="false";
3368
				#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
3369
				#$conf["external::callShell"]["doNotRun"]=$doNotRun;
3370
				#參考資料:
3371
				#exec=>http://php.net/manual/en/function.exec.php
3372
				#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
3373
				#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
3374
				#備註:
3375
				#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
3376
				#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
3377
				$callShell=external::callShell($conf["external::callShell"]);
3378
				unset($conf["external::callShell"]);
226 liveuser 3379
 
237 liveuser 3380
				#如果解析檔案資訊失敗
3381
				if($callShell["status"]==="false"){
226 liveuser 3382
 
237 liveuser 3383
					#設置錯誤識別
3384
					$result["status"]="false";
48 liveuser 3385
 
237 liveuser 3386
					#設置錯誤資訊
3387
					$result["error"]=$callShell;
48 liveuser 3388
 
237 liveuser 3389
					#回傳結果
3390
					return $result;
226 liveuser 3391
 
237 liveuser 3392
					}#if end
239 liveuser 3393
 
237 liveuser 3394
				}#else end
239 liveuser 3395
 
237 liveuser 3396
			#debug
3397
			#var_dump(__LINE__,$callShell);exit;
226 liveuser 3398
 
48 liveuser 3399
			#預設的 pgp 簽署方式
3400
			$micalg="micalg=\"pgp-sha512\"";
226 liveuser 3401
 
48 liveuser 3402
			#如果輸出結尾不是 "-----END PGP SIGNATURE-----"
3403
			if($callShell["output"][count($callShell["output"])-1]!=="-----END PGP SIGNATURE-----"){
226 liveuser 3404
 
48 liveuser 3405
				#設置錯誤識別
3406
				$result["status"]="false";
3407
 
3408
				#設置錯誤資訊
3409
				$result["error"]=$callShell;
3410
 
3411
				#回傳結果
3412
				return $result;
226 liveuser 3413
 
48 liveuser 3414
				}#if end
226 liveuser 3415
 
237 liveuser 3416
			#取得 PGP SIGNATURE
3417
			$signDataOfGPG=$callShell["content"];
239 liveuser 3418
 
237 liveuser 3419
			#debug
3420
			#var_dump(__LINE__,"gpg data",$signDataOfGPG);
226 liveuser 3421
 
48 liveuser 3422
			#head 增加表示有 GPG 簽署
3423
			$head=$head."Security: GPG signed"."\r\n";
226 liveuser 3424
 
48 liveuser 3425
			#函式說明:
3426
			#建立以圖片(PNG格式)呈現的驗證碼.
3427
			#回傳的解果:
3428
			#$result["status"],執行是否正常,"true"代表執行成功,"false"代表執行失敗.
3429
			#$result["error"],錯誤訊息.
3430
			#$result["function"],檔前執行的函數名稱.
3431
			#$result["randNumberWord"],傳驗證碼的內容.
3432
			#$result["imgAddress"],包含src圖片的位置與名稱.
3433
			#$result["imgSrcVal"],放在src裏面的圖片位置與名稱.
3434
			#必填參數:
3435
			#$conf["imgAddressAndName"],字串,爲驗證碼圖片儲存的位置與名稱,副檔名程式會自動產生
3436
			$conf["authenticate::validationCode"]["imgAddressAndName"]="/tmp/xxx.png";
3437
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
3438
			$conf["authenticate::validationCode"]["fileArgu"]=__FILE__;
3439
			#可省略參數:
3440
			#$conf["num"],字串,爲驗證碼的位數,請輸入阿拉伯數字,預設為"8"位數.
3441
			#$conf["num"]="8";
3442
			#$conf["disableImg"],字串,是否要取消驗證碼圖片的輸出,"true"為要取消,預設為"false"為不取消
3443
			$conf["authenticate::validationCode"]["disableImg"]="true";
3444
			#$conf["imgToData"],字串,預設為"true"代表將圖片轉存成base64圖片,並將原始圖片移除;反之為"false"
3445
			#$conf["imgToData"]="true";
3446
			#$conf["class"],字串,圖片要套用的css樣式類別.
3447
			#$conf["class"]="";
3448
			#$conf["content"],字串陣列,允許的亂數陣列內容,預設爲(1~9 and A~Z).
3449
			#$conf["content"]=array();
3450
			#參考資料:
3451
			#無.
3452
			#備註:
3453
			#無.
3454
			$validationCode=authenticate::validationCode($conf["authenticate::validationCode"]);
3455
			unset($conf["authenticate::validationCode"]);
226 liveuser 3456
 
48 liveuser 3457
			#如果檢查失敗
3458
			if($validationCode["status"]==="false"){
226 liveuser 3459
 
48 liveuser 3460
				#設置錯誤識別
3461
				$result["status"]="false";
226 liveuser 3462
 
48 liveuser 3463
				#設置錯誤訊息
3464
				$result["error"]=$validationCode;
226 liveuser 3465
 
48 liveuser 3466
				#回傳結果
3467
				return $result;
226 liveuser 3468
 
48 liveuser 3469
				}#if end
226 liveuser 3470
 
48 liveuser 3471
			#初始化 boundary
237 liveuser 3472
			$gpgBoundary=$validationCode["randNumberWord"];
226 liveuser 3473
 
48 liveuser 3474
			#初始化 boundary start
237 liveuser 3475
			$gpgBoundaryS="--".$gpgBoundary;
226 liveuser 3476
 
48 liveuser 3477
			#初始化 boundary end
237 liveuser 3478
			$gpgBoundaryE=$gpgBoundaryS."--";
226 liveuser 3479
 
48 liveuser 3480
			#將 data 用新的 boundary 包起來
237 liveuser 3481
			$body=$gpgBoundaryS."\r\n".$body."\r\n";
226 liveuser 3482
 
48 liveuser 3483
			#8個空格
3484
			$eightSpace="        ";
226 liveuser 3485
 
48 liveuser 3486
			#描述內容為 gpg key 簽署的 head 資訊,"protocol"要空8格
237 liveuser 3487
			$gpgData="Content-Type: multipart/signed; ".$micalg.";"."\r\n".$eightSpace."protocol=\"application/pgp-signature\"; boundary=\"".$gpgBoundary."\"\r\n";
226 liveuser 3488
 
237 liveuser 3489
			#描述內容為 gpg key 簽署的 head 資訊 需要 word wrap
3490
			$gpgData=wordwrap($gpgData,70,"\r\n",true);
3491
 
226 liveuser 3492
			#增加描述用於 sign 的 gpg pub key
237 liveuser 3493
			$signDataOfGPGhead="Content-Type: application/pgp-signature; name=\"signature.asc\""."\r\n"."Content-Description: This is a digitally signed message part"."\r\n\r\n";
239 liveuser 3494
 
237 liveuser 3495
			#gpg header 需要 word wrap
3496
			$signDataOfGPG=wordwrap($signDataOfGPGhead,70,"\r\n",true).$signDataOfGPG."\r\n";
226 liveuser 3497
 
48 liveuser 3498
			#設置gpg key簽署的資訊
237 liveuser 3499
			$body=$body.$gpgBoundaryS."\r\n".$signDataOfGPG."\r\n".$gpgBoundaryE."\r\n";
226 liveuser 3500
 
48 liveuser 3501
			#取得放置於head的Contet-Type描述
3502
			$contentDescInHead=&$gpgData;
239 liveuser 3503
 
237 liveuser 3504
			#串接 data
3505
			#$body=$contentDescInHead."\r\n\r\n".$body;
226 liveuser 3506
 
48 liveuser 3507
			}#if end
239 liveuser 3508
 
237 liveuser 3509
		#串接 data
3510
		$body=$contentDescInHead."\r\n\r\n".$body;
226 liveuser 3511
 
237 liveuser 3512
		#組合head與body
3513
		$data=$head.$body;
226 liveuser 3514
 
48 liveuser 3515
		#Send the DATA command to start message body
3516
		if(\PEAR::isError($smtp->data($data))){
226 liveuser 3517
 
48 liveuser 3518
			#設置錯誤識別
3519
			$result["status"]="false";
226 liveuser 3520
 
48 liveuser 3521
			#設置錯誤訊息
3522
			$result["error"]="Unable to send data:".$data;
226 liveuser 3523
 
48 liveuser 3524
			#回傳結果
3525
			return $result;
226 liveuser 3526
 
48 liveuser 3527
			}#if end
226 liveuser 3528
 
48 liveuser 3529
		#使用完畢後要關閉連線
3530
		$smtp->disconnect();
226 liveuser 3531
 
48 liveuser 3532
		#設置執行正常
3533
		$result["status"]="true";
226 liveuser 3534
 
48 liveuser 3535
		#回傳結果
3536
		return $result;
226 liveuser 3537
 
48 liveuser 3538
		}#function pear_smtp_send end
226 liveuser 3539
 
3 liveuser 3540
	}#class mail end
226 liveuser 3541
 
3542
?>