Subversion Repositories php-qbpwcf

Rev

Rev 30 | Rev 48 | Go to most recent revision | 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.
30 liveuser 6
    Copyright (C) 2014~2025 Min-Jhin,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){
52
 
53
		#取得當前執行的函式
54
		$result["function"]=__FUNCTION__;
55
 
56
		#設置執行不正常
57
		$result["status"]="false";
58
 
59
		#設置執行錯誤
60
		$result["error"][]=__NAMESPACE__ ."/".$method."() 不存在!";
61
 
62
		#設置所丟入的參數
63
		$result["error"][]=$arguments;
64
 
65
		#回傳結果
66
		return $result;
67
 
68
		}#function __call end
69
 
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){
88
 
89
		#取得當前執行的函式
90
		$result["function"]=__FUNCTION__;
91
 
92
		#設置執行不正常
93
		$result["status"]="false";
94
 
95
		#設置執行錯誤
96
		$result["error"][]="欲呼叫的". __NAMESPACE__ ."/".$method."() 不存在!";
97
 
98
		#設置所丟入的參數
99
		$result["error"][]=$arguments;
100
 
101
		#回傳結果
102
		return $result;
103
 
104
		}#function __callStatic end
105
 
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"){
136
 
137
			#設置執行失敗
138
			$result["status"]="false";
139
 
140
			#設置執行錯誤訊息
141
			$result["error"][]="\$conf變數須為陣列形態";
142
 
143
			#如果傳入的參數為 null
144
			if($conf==null){
145
 
146
				#設置執行錯誤訊息
147
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
148
 
149
				}#if end
150
 
151
			#回傳結果
152
			return $result;
153
 
154
			}#if end
155
 
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");
174
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); 
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");
183
		#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double"); 
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"]);
193
 
194
		#如果檢查失敗
195
		if($checkArguments["status"]=="false"){
196
 
197
			#設置錯誤識別
198
			$result["status"]="false";
199
 
200
			#設置錯誤訊息
201
			$result["error"]=$checkArguments;
202
 
203
			#回傳結果
204
			return $result;
205
 
206
			}#if end
207
 
208
		#如果檢查不通過
209
		if($checkArguments["passed"]=="false"){
210
 
211
			#設置錯誤識別
212
			$result["status"]="false";
213
 
214
			#設置錯誤訊息
215
			$result["error"]=$checkArguments;
216
 
217
			#回傳結果
218
			return $result;
219
 
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){
228
 
229
			#設置執行不正常
230
			$result["status"]="false";
231
 
232
			#設置錯誤訊息
233
			$result["error"]=\imap_last_error();
234
 
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"){
275
 
276
			#設置執行失敗
277
			$result["status"]="false";
278
 
279
			#設置執行錯誤訊息
280
			$result["error"][]="\$conf變數須為陣列形態";
281
 
282
			#如果傳入的參數為 null
283
			if($conf==null){
284
 
285
				#設置執行錯誤訊息
286
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
287
 
288
				}#if end
289
 
290
			#回傳結果
291
			return $result;
292
 
293
			}#if end
294
 
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");
313
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); 
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");
322
		#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double"); 
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"]);
332
 
333
		#如果檢查失敗
334
		if($checkArguments["status"]=="false"){
335
 
336
			#設置錯誤識別
337
			$result["status"]="false";
338
 
339
			#設置錯誤訊息
340
			$result["error"]=$checkArguments;
341
 
342
			#回傳結果
343
			return $result;
344
 
345
			}#if end
346
 
347
		#如果檢查不通過
348
		if($checkArguments["passed"]=="false"){
349
 
350
			#設置錯誤識別
351
			$result["status"]="false";
352
 
353
			#設置錯誤訊息
354
			$result["error"]=$checkArguments;
355
 
356
			#回傳結果
357
			return $result;
358
 
359
			}#if end
360
 
361
		#如果中斷與mailServer的連線失敗
362
		if(\imap_close($conf["mailConnection"])==false){
363
 
364
			#設置執行不正常
365
			$result["status"]="false";
366
 
367
			#設置錯誤訊息
368
			$result["error"][]="中斷與 imap Server 的連線失敗";
369
 
370
			#回傳結果
371
			return $result;
372
 
373
			}#if end
374
 
375
		#設置執行正常
376
		$result["status"]="true";
377
 
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
	#無法寄送成功?
410
	*/		
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"){
421
 
422
			#設置執行失敗
423
			$result["status"]="false";
424
 
425
			#設置執行錯誤訊息
426
			$result["error"][]="\$conf變數須為陣列形態";
427
 
428
			#如果傳入的參數為 null
429
			if($conf==null){
430
 
431
				#設置執行錯誤訊息
432
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
433
 
434
				}#if end
435
 
436
			#回傳結果
437
			return $result;
438
 
439
			}#if end
440
 
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");
459
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); 
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");
468
		#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double"); 
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"]);
478
 
479
		#如果檢查失敗
480
		if($checkArguments["status"]=="false"){
481
 
482
			#設置錯誤識別
483
			$result["status"]="false";
484
 
485
			#設置錯誤訊息
486
			$result["error"]=$checkArguments;
487
 
488
			#回傳結果
489
			return $result;
490
 
491
			}#if end
492
 
493
		#如果檢查不通過
494
		if($checkArguments["passed"]=="false"){
495
 
496
			#設置錯誤識別
497
			$result["status"]="false";
498
 
499
			#設置錯誤訊息
500
			$result["error"]=$checkArguments;
501
 
502
			#回傳結果
503
			return $result;
504
 
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"])){
518
 
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"){
539
 
540
			#設置錯誤訊息
541
			$result["error"]=$mailConnection;
542
 
543
			#設置執行失敗
544
			$result["status"]="false";
545
 
546
			#回傳結果
547
			return $result;
548
 
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"]));
568
 
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"){
590
 
591
			#設置執行失敗
592
			$result["status"]="false";
593
 
594
			#設置錯誤訊息
595
			$result["error"]=$imapLogout;
596
 
597
			#回傳結果
598
			return $result;
599
 
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
	#備註:
668
	#無.
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"){
680
 
681
			#設置執行失敗
682
			$result["status"]="false";
683
 
684
			#設置執行錯誤訊息
685
			$result["error"][]="\$conf變數須為陣列形態";
686
 
687
			#如果傳入的參數為 null
688
			if($conf==null){
689
 
690
				#設置執行錯誤訊息
691
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
692
 
693
				}#if end
694
 
695
			#回傳結果
696
			return $result;
697
 
698
			}#if end
699
 
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");
718
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); 
719
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","array","string","string","string","string");
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");
727
		#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double"); 
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"]);
737
 
738
		#如果檢查失敗
739
		if($checkArguments["status"]=="false"){
740
 
741
			#設置錯誤識別
742
			$result["status"]="false";
743
 
744
			#設置錯誤訊息
745
			$result["error"]=$checkArguments;
746
 
747
			#回傳結果
748
			return $result;
749
 
750
			}#if end
751
 
752
		#如果檢查不通過
753
		if($checkArguments["passed"]=="false"){
754
 
755
			#設置錯誤識別
756
			$result["status"]="false";
757
 
758
			#設置錯誤訊息
759
			$result["error"]=$checkArguments;
760
 
761
			#回傳結果
762
			return $result;
763
 
764
			}#if end
765
 
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"]);
783
 
784
		#如果檢查檔案失敗
785
		if($checkMutiFileExist["status"]=="false"){
786
 
787
			#設置錯誤識別
788
			$result["status"]="false";
789
 
790
			#設置錯誤訊息
791
			$result["error"]=$checkMutiFileExist;
792
 
793
			#回傳結果
794
			return $result;
795
 
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"]);
814
 
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
830
 
831
		#取得 $systemTime	
832
		$systemTime=time::getMicrotime();
833
 
834
		#要傳送的信件資訊
835
		$mailFileHeader="From: ".$conf["mailerNameDisplay"]." <".$conf["mailerMailDisplay"].">\r\n";
836
 
837
		#第一個人主要收件人
838
		$mailFileHeader=$mailFileHeader."To: ".$conf["receiverNameDisplay"][0]." "."<".$conf["receiverMailDisplay"][0].">\r\n";			
839
 
840
		#如果有其餘收件人
841
		if(count($conf["receiverNameDisplay"])>1){
842
 
843
			#副本寄送處的資訊開始
844
			$mailFileHeader=$mailFileHeader."Cc: ";
845
 
846
			}#if end
847
 
848
		#針對其餘收件人的地址
849
		for($i=1;$i<count($conf["receiverNameDisplay"]);$i++){
850
 
851
			#如果不是最後一筆
852
			if($i!=count($conf["receiverNameDisplay"])-1){
853
 
854
				$mailFileHeader=$mailFileHeader.$conf["receiverNameDisplay"][$i]." <".$conf["receiverMailDisplay"][$i].">,";
855
 
856
				}#if end
857
 
858
			#反之是最後一筆
859
			else{
860
 
861
				$mailFileHeader=$mailFileHeader.$conf["receiverNameDisplay"][$i]." <".$conf["receiverMailDisplay"][$i].">\r\n";
862
 
863
				}#else end				
864
 
865
			}#for end
866
 
867
		$mailFileHeader=$mailFileHeader."Subject: ".$conf["subject"]."\r\n";
868
 
869
		#初始化信件本文
870
		$mailFileContent="";
871
 
872
		#初始化 boundary
873
		$boundary="001a11c30ce8aec3480533bfa9a9";
874
 
875
		#初始化 boundary start
876
		$boundaryS="--".$boundary;
877
 
878
		#初始化 boundary end	
879
		$boundaryE=$boundaryS."--";
880
 
881
		#設置信件本文(純文字與html兩種)				
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";
893
		$mailFileContent=$mailFileContent.$boundaryE."\r\n";			
894
 
895
		#依據規定,每列不得大於70的字元
896
		$mailFileContent==wordwrap($mailFileContent,70,"\r\n",true);
897
 
898
		#如果有設定要上傳附件
899
		if(isset($conf["attachment"])){
900
 
901
			#依據每個附件
902
			for($i=0;$i<count($conf["attachment"]);$i++){
903
 
904
				#初始化寄送附件的語法
905
				$attachment="";
906
 
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"]);
924
 
925
				#如果檢查失敗
926
				if($checkMutiFileExist["status"]=="false"){
927
 
928
					#設置錯誤識別
929
					$result["status"]="false";
930
 
931
					#設置錯誤資訊
932
					$result["error"]=$checkMutiFileExist;
933
 
934
					#回傳結果
935
					return $result;
936
 
937
					}#if end
938
 
939
				#如果檔案不存在
940
				if($checkMutiFileExist["varExist"][0]=="false"){
941
 
942
					#設置錯誤識別
943
					$result["status"]="false";
944
 
945
					#設置錯誤資訊
946
					$result["error"]=$checkMutiFileExist;
947
 
948
					#回傳結果
949
					return $result;
950
 
951
					}#if end
952
 
953
				#如果是第一個附件
954
				if($i==0){
955
 
956
					#在前面加上 multipart/mixed 的 boundary
957
					$mailFileContent="Content-Type: multipart/mixed; boundary=".$boundary."\r\n\r\n".$mailFileContent;
958
 
959
					}#if end
960
 
961
				#如果 $conf["attachmentName"] 不存在
962
				if(!isset($conf["attachmentName"])){
963
 
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"]);
982
 
983
					#如果解析檔案資訊失敗		
984
					if($getFileAddressAndNameAndFileExtention["status"]=="false"){
985
 
986
						#設置錯誤識別
987
						$result["status"]="false";
988
 
989
						#設置錯誤資訊
990
						$result["error"]=$getFileAddressAndNameAndFileExtention;
991
 
992
						#回傳結果
993
						return $result;
994
 
995
						}#if end			
996
 
997
					#設定附件名稱
998
					$conf["attachmentName"][$i]=$getFileAddressAndNameAndFileExtention["fullFileName"];
999
 
1000
					}#if end
1001
 
1002
				#反之如果 $conf["attachmentName"][$i] 不存在
1003
				else if(!isset($conf["attachmentName"][$i])){
1004
 
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"]);
1023
 
1024
					#如果解析檔案資訊失敗		
1025
					if($getFileAddressAndNameAndFileExtention["status"]=="false"){
1026
 
1027
						#設置錯誤識別
1028
						$result["status"]="false";
1029
 
1030
						#設置錯誤資訊
1031
						$result["error"]=$getFileAddressAndNameAndFileExtention;
1032
 
1033
						#回傳結果
1034
						return $result;
1035
 
1036
						}#if end			
1037
 
1038
					#設定附件名稱
1039
					$conf["attachmentName"][$i]=$getFileAddressAndNameAndFileExtention["fullFileName"];
1040
 
1041
					}#if end
1042
 
1043
				#如果 $conf["attachmentMimeType"] 不存在
1044
				if(!isset($conf["attachmentMimeType"])){
1045
 
1046
					#設定檔案類型
1047
					$conf["attachmentMimeType"][$i]="application/*";
1048
 
1049
					}#if end	
1050
 
1051
				#反之如果 $conf["attachmentMimeType"][$i] 不存在	
1052
				if(!isset($conf["attachmentMimeType"][$i])){
1053
 
1054
					$conf["attachmentMimeType"][$i]="application/*";
1055
 
1056
					}#if end
1057
 
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";
1062
				$attachment=$attachment."Content-Transfer-Encoding: base64\r\n";			
1063
				$attachment=$attachment."X-Attachment-Id: f_io1ikfii".$i."\r\n";
1064
 
1065
				#將檔案用base64加密					
1066
				$base64fileStr=base64_encode(file_get_contents($conf["attachment"][$i]));
1067
 
1068
				#依據規定,每列不得大於70的字元
1069
				$wordwrapedFileStr=wordwrap($base64fileStr,70,"\r\n",true);
1070
 
1071
				#斷行後附加檔案字串
1072
				$attachment=$attachment."\r\n".$wordwrapedFileStr."\r\n";	
1073
 
1074
				#如果是最後一個附件
1075
				if($i==count($conf["attachment"])-1){
1076
 
1077
					#混合資料結尾
1078
					$attachment=$attachment.$boundary."\r\n";
1079
 
1080
					}#if end	
1081
 
1082
				#增加到信件內文的結尾
1083
				$mailFileContent=$mailFileContent.$attachment;
1084
 
1085
				}#for end
1086
 
1087
			}#if end
1088
 
1089
		#建立要寄送的郵件檔案
1090
		#函式說明:
1091
		#建立暫存目錄與回傳暫存檔案名稱路徑 
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"]);
3 liveuser 1108
 
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
1122
 
1123
		#取得要寄送的郵件檔案
1124
		$mailFile=$createTempFile["content"];
1125
 
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();
1156
 
1157
		#設置要用 ssl
1158
		$paramArray[]="--ssl-reqd";
1159
 
1160
		#如果為 "levelForCheckSSL" 為 "none"
1161
		if($conf["levelForCheckSSL"]==="none"){
1162
 
1163
			#設置不用確認ssl符合規範
1164
			$paramArray[]="-k";
1165
 
1166
			}#if end
1167
 
1168
		#設置要設定url
1169
		$paramArray[]="--url";
1170
 
1171
		#設置smtp server
1172
		$paramArray[]=$conf["mailServer"];
1173
 
1174
		#設置指定使用者名稱
1175
		$paramArray[]="-u";
1176
 
1177
		#設置使用名稱與密碼
1178
		$paramArray[]=$conf["username"].":".$conf["password"];
1179
 
1180
		#設置要指定寄信來源顯示的名稱
1181
		$paramArray[]="--mail-from";
1182
 
1183
		#設置寄信來源顯示的名稱
1184
		$paramArray[]=$conf["mailerMailDisplay"];
1185
 
1186
		#有幾個收件人就執行幾次
1187
		foreach($conf["receiverMail"] as $mailTo){
1188
 
1189
			#指定收件人的參數
1190
			$paramArray[]="--mail-rcpt";
1191
 
1192
			#串接收件人
1193
			$paramArray[]=$mailTo;
1194
 
1195
			}#for end
1196
 
1197
		#指定mail檔案
1198
		$paramArray[]="--upload-file";
1199
		$paramArray[]=$mailFile;
1200
 
1201
		#看過程
1202
		$paramArray[]="-v";
1203
 
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__的內容,預設為當前檔案的路徑與名稱.
1234
		#$conf["fileArgu"]=""; 
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"){
1244
 
1245
			#如果 "levelForCheckSSL" 為 "loose"
1246
			if($conf["levelForCheckSSL"]==="loose"){
1247
 
1248
				#加上 "-k" 參數,這次不用符合ssl規範
1249
				$paramArray[]="-k";
1250
 
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__的內容,預設為當前檔案的路徑與名稱.
1281
				#$conf["fileArgu"]=""; 
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"]);
1288
 
1289
				#如果 $external["callShell"] 等於 "false"
1290
				if($external["callShell"]["status"]==="false"){
1291
 
1292
					#設置錯誤識別
1293
					$result["status"]="false";
1294
 
1295
					#設置錯誤訊息
1296
					$result["error"]=$external["callShell"];
1297
 
1298
					#回傳結果
1299
					return $result;
1300
 
1301
					}#if end
1302
 
1303
				}#if end
1304
 
1305
			#反之
1306
			else{
1307
 
1308
				#設置錯誤識別
1309
				$result["status"]="false";
1310
 
1311
				#設置錯誤訊息
1312
				$result["error"]=$external["callShell"];
1313
 
1314
				#回傳結果
1315
				return $result;
1316
 
1317
				}#else end`
1318
 
1319
			}#if end
1320
 
1321
		#取得較完整的指令
1322
		$result["cmd"]=$external["callShell"]["cmd"];
1323
 
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";
1343
 
1344
			#設置錯誤訊息
1345
			$result["error"]=$delMailFile;
1346
 
1347
			#回傳結果
1348
			return $result;
1349
 
1350
			}#if end
1351
 
1352
		#可以執行到這邊,就表示十之八九寄信成功了
1353
		$result["status"]="true";
1354
 
1355
		#回傳結果
1356
		return $result;
1357
 
1358
		}#function curlSmtp end
1359
 
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){
1412
 
1413
		#初始化要回傳的結果
1414
		$result=array();
1415
 
1416
		#儲存當前執行的函數
1417
		$result["function"]=__FUNCTION__;
1418
 
1419
		#如果 $conf 不為陣列
1420
		if(gettype($conf)!="array"){
1421
 
1422
			#設置執行失敗
1423
			$result["status"]="false";
1424
 
1425
			#設置執行錯誤訊息
1426
			$result["error"][]="\$conf變數須為陣列形態";
1427
 
1428
			#如果傳入的參數為 null
1429
			if($conf==null){
1430
 
1431
				#設置執行錯誤訊息
1432
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
1433
 
1434
				}#if end
1435
 
1436
			#回傳結果
1437
			return $result;
1438
 
1439
			}#if end
1440
 
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");
1459
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); 
1460
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","array","array","array","array","string");
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");
1468
		#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double"); 
1469
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array","array","array","string","string","string","array","array","string","string");
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"]);
1478
 
1479
		#如果檢查失敗
1480
		if($checkArguments["status"]=="false"){
1481
 
1482
			#設置錯誤識別
1483
			$result["status"]="false";
1484
 
1485
			#設置錯誤訊息
1486
			$result["error"]=$checkArguments;
1487
 
1488
			#回傳結果
1489
			return $result;
1490
 
1491
			}#if end
1492
 
1493
		#如果檢查不通過
1494
		if($checkArguments["passed"]=="false"){
1495
 
1496
			#設置錯誤識別
1497
			$result["status"]="false";
1498
 
1499
			#設置錯誤訊息
1500
			$result["error"]=$checkArguments;
1501
 
1502
			#回傳結果
1503
			return $result;
1504
 
1505
			}#if end
1506
 
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"]);
1524
 
1525
		#如果檢查檔案失敗
1526
		if($checkMutiFileExist["status"]=="false"){
1527
 
1528
			#設置錯誤識別
1529
			$result["status"]="false";
1530
 
1531
			#設置錯誤訊息
1532
			$result["error"]=$checkMutiFileExist;
1533
 
1534
			#回傳結果
1535
			return $result;
1536
 
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"]);
1555
 
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
1571
 
1572
		#初始化寄信的command
1573
		#$mailCmd="";
1574
 
1575
		#初始化寄信的指令
1576
		$mailCmdArray=array();		
1577
 
1578
		#初始化移除信件檔案的指令
1579
		$delMailFileCmd=array();
1580
 
1581
		#取得 $systemTime	
1582
		$systemTime=time::getMicrotime();
1583
 
1584
		#要傳送的信件資訊
1585
		$fromInfo="From: ".$conf["mailerNameDisplay"]." <".$conf["mailerMailDisplay"].">\r\n";
1586
 
1587
		#初始化信件的 header
1588
		$mailFileHeader="";
1589
 
1590
		#依據 $conf["receiverMail"] 的數量
1591
		for($i=0;$i<count($conf["receiverMail"]);$i++){
1592
 
1593
			#串接寄件人的資訊
1594
			$mailFileHeader=$mailFileHeader.$fromInfo;
1595
 
1596
			#如果第$i筆信件的收件人陣列不存在
1597
			if(!isset($conf["receiverMail"][$i])){
1598
 
1599
				#設置執行不正常
1600
				$result["status"]="false";
1601
 
1602
				#設置錯誤訊息
1603
				$result["error"][]="第".($i+1)."筆收件人陣列不存在";
1604
 
1605
				#回傳結果
1606
				return $result;
1607
 
1608
				}#if end
1609
 
1610
			#反之存在但形態不為陣列
1611
			if(gettype($conf["receiverMail"][$i])!="array"){
1612
 
1613
				#設置執行不正常
1614
				$result["status"]="false";
1615
 
1616
				#設置錯誤訊息
1617
				$result["error"][]="第".($i+1)."筆收件人陣列形態不正確";
1618
 
1619
				#回傳結果
1620
				return $result;
1621
 
1622
				}#if end	
1623
 
1624
			#如果第$i筆信件的收件人名稱不存在
1625
			if(!isset($conf["receiverNameDisplay"][$i])){
1626
 
1627
				#設為第$i筆信件的收件人陣列
1628
				$conf["receiverNameDisplay"][$i]=$conf["receiverMail"][$i];
1629
 
1630
				}#if end
1631
 
1632
			#第$i筆信件收件人名稱陣列的第一個元素不存在
1633
			else if(!isset($conf["receiverNameDisplay"][$i][0])){
1634
 
1635
				#設置執行不正常
1636
				$result["status"]="false";
1637
 
1638
				#設置錯誤訊息
1639
				$result["error"][]="第".($i+1)."筆收件人名稱陣列的第一個收件人名稱不存在";
1640
 
1641
				#回傳結果
1642
				return $result;
1643
 
1644
				}#if end
1645
 
1646
			#如果第$i筆信件的收件人信箱名稱不存在
1647
			if(!isset($conf["receiverMailDisplay"][$i])){
1648
 
1649
				#設為第$i筆信件的收件人陣列
1650
				$conf["receiverMailDisplay"][$i]=$conf["receiverMail"][$i];
1651
 
1652
				}#if end
1653
 
1654
			#第$i筆信件收件人信箱名稱陣列的第一個元素不存在
1655
			else if(!isset($conf["receiverNameDisplay"][$i][0])){
1656
 
1657
				#設置執行不正常
1658
				$result["status"]="false";
1659
 
1660
				#設置錯誤訊息
1661
				$result["error"][]="第".($i+1)."筆收件人信箱名稱陣列的第一個收件人信箱名稱不存在";
1662
 
1663
				#回傳結果
1664
				return $result;
1665
 
1666
				}#if end						
1667
 
1668
			#第一個人為主要收件人
1669
			$mailFileHeader=$mailFileHeader."To: ".$conf["receiverNameDisplay"][$i][0]." "."<".$conf["receiverMailDisplay"][$i][0].">\r\n";			
1670
 
1671
			#如果有其餘收件人
1672
			if(count($conf["receiverNameDisplay"][$i])>1){
1673
 
1674
				#副本寄送處的資訊開始
1675
				$mailFileHeader=$mailFileHeader."Cc: ";
1676
 
1677
				}#if end
1678
 
1679
			#針對其餘收件人的地址
1680
			for($j=1;$j<count($conf["receiverNameDisplay"][$i]);$j++){
1681
 
1682
				#如果不是最後一筆
1683
				if($j!=count($conf["receiverNameDisplay"][$i])-1){
1684
 
1685
					#串接並加上逗號
1686
					$mailFileHeader=$mailFileHeader.$conf["receiverNameDisplay"][$i][$j]." <".$conf["receiverMailDisplay"][$i][$j].">,";
1687
 
1688
					}#if end
1689
 
1690
				#反之是最後一筆
1691
				else{
1692
 
1693
					#串接並接上換行符號
1694
					$mailFileHeader=$mailFileHeader.$conf["receiverNameDisplay"][$i][$j]." <".$conf["receiverMailDisplay"][$i][$j].">\r\n";
1695
 
1696
					}#else end				
1697
 
1698
				}#for end
1699
 
1700
			#設置信件標題
1701
			$mailFileHeader=$mailFileHeader."Subject: ".$conf["subject"][$i]."\r\n";
1702
 
1703
			#設置 MIME-Version
1704
			$mailFileHeader=$mailFileHeader."MIME-Version: 1.0\r\n";
1705
 
1706
			#初始化信件本文
1707
			$mailFileContent="";
1708
 
1709
			#設置信件本文(純文字與html兩種)				
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";
1724
 
1725
			#如果有設定要上傳附件
1726
			if(isset($conf["attachment"])){
1727
 
1728
				#如果第 $i+1 封信件有指定 附件
1729
				if(isset($conf["attachment"][$i])){
1730
 
1731
					#如果類型正確
1732
					if(gettype($conf["attachment"][$i])=="array"){
1733
 
1734
						#依據每個附件
1735
						for($j=0;$j<count($conf["attachment"][$i]);$j++){
1736
 
1737
							#初始化寄送附件的語法
1738
							$attachment="";
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"]); 
1754
							unset($conf["fileAccess::checkMultiFileExist"]);
1755
 
1756
							#如果檢查失敗
1757
							if($checkMutiFileExist["status"]=="false"){
1758
 
1759
								#設置錯誤識別
1760
								$result["status"]="false";
1761
 
1762
								#設置錯誤資訊
1763
								$result["error"]=$checkMutiFileExist;
1764
 
1765
								#回傳結果
1766
								return $result;
1767
 
1768
								}#if end
1769
 
1770
							#如果檔案不存在
1771
							if($checkMutiFileExist["varExist"][0]=="false"){
1772
 
1773
								#設置錯誤識別
1774
								$result["status"]="false";
1775
 
1776
								#設置錯誤資訊
1777
								$result["error"]=$checkMutiFileExist;
1778
 
1779
								#回傳結果
1780
								return $result;
1781
 
1782
								}#if end
1783
 
1784
							#如果是第一個附件
1785
							if($j==0){
1786
 
1787
								#在前面加上 multipart/mixed 的 boundary
1788
								$mailFileContent="Content-Type: multipart/mixed; boundary=001a11c30ce8aec3550533bfa9ab\r\n\r\n".$mailFileContent;
1789
 
1790
								}#if end
1791
 
1792
							#如果 $conf["attachmentName"][$i] 不存在
1793
							if(!isset($conf["attachmentName"][$i])){
1794
 
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"]);
1813
 
1814
								#如果解析檔案資訊失敗		
1815
								if($getFileAddressAndNameAndFileExtention["status"]=="false"){
1816
 
1817
									#設置錯誤識別
1818
									$result["status"]="false";
1819
 
1820
									#設置錯誤資訊
1821
									$result["error"]=$getFileAddressAndNameAndFileExtention;
1822
 
1823
									#回傳結果
1824
									return $result;
1825
 
1826
									}#if end			
1827
 
1828
								#設定附件名稱
1829
								$conf["attachmentName"][$i][$j]=$getFileAddressAndNameAndFileExtention["fullFileName"];
1830
 
1831
								}#if end
1832
 
1833
							#反之如果 $conf["attachmentName"][$i][$j] 不存在
1834
							else if(!isset($conf["attachmentName"][$i][$j])){
1835
 
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"]);
1854
 
1855
								#如果解析檔案資訊失敗		
1856
								if($getFileAddressAndNameAndFileExtention["status"]=="false"){
1857
 
1858
									#設置錯誤識別
1859
									$result["status"]="false";
1860
 
1861
									#設置錯誤資訊
1862
									$result["error"]=$getFileAddressAndNameAndFileExtention;
1863
 
1864
									#回傳結果
1865
									return $result;
1866
 
1867
									}#if end			
1868
 
1869
								#設定附件名稱
1870
								$conf["attachmentName"][$i][$j]=$getFileAddressAndNameAndFileExtention["fullFileName"];
1871
 
1872
								}#if end
1873
 
1874
							#如果 $conf["attachmentMimeType"][$i][$j] 不存在
1875
							if(!isset($conf["attachmentMimeType"][$i])){
1876
 
1877
								#設定檔案類型
1878
								$conf["attachmentMimeType"][$i][$j]="application/*";
1879
 
1880
								}#if end	
1881
 
1882
							#反之如果 $conf["attachmentMimeType"][$i][$j] 不存在	
1883
							else if(!isset($conf["attachmentMimeType"][$i][$j])){
1884
 
1885
								$conf["attachmentMimeType"][$i][$j]="application/*";
1886
 
1887
								}#if end
1888
 
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";
1893
							$attachment=$attachment."Content-Transfer-Encoding: base64\r\n";			
1894
							$attachment=$attachment."X-Attachment-Id: f_io1ikfii".$i."_".$j."\r\n";
1895
 
1896
							#將檔案用base64加密					
1897
							$base64fileStr=base64_encode(file_get_contents($conf["attachment"][$i][$j]));
1898
 
1899
							#依據規定,每列不得大於70的字元
1900
							$wordwrapedFileStr=wordwrap($base64fileStr,70,"\r\n",true);
1901
 
1902
							#斷行後附加檔案字串
1903
							$attachment=$attachment."\r\n".$wordwrapedFileStr."\r\n";	
1904
 
1905
							#如果是最後一個附件
1906
							if($j==count($conf["attachment"][$i])-1){
1907
 
1908
								#混合資料結尾
1909
								$attachment=$attachment."--001a11c30ce8aec3550533bfa9ab--\r\n";
1910
 
1911
								}#if end	
1912
 
1913
							#增加到信件內文的結尾
1914
							$mailFileContent=$mailFileContent.$attachment;
1915
 
1916
							}#for end
1917
 
1918
						}#if end
1919
 
1920
					}#if end
1921
 
1922
				}#if end
1923
 
1924
			#要寄送的郵件檔案路徑與名稱
1925
			$mailFile=".curlSmtp/mail_at_".$systemTime.".mail";	
1926
 
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"]);
1952
 
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
1966
 
1967
			#取得建立好的檔案名稱
1968
			$mailFile=$writeTextIntoFile["fileInfo"]["createdFilePathAndName"];
1969
 
1970
			#初始化收件人字串
1971
			$rcptStr="";
1972
 
1973
			#有幾個收件人就執行幾次
1974
			foreach($conf["receiverMail"][$i] as $mailTo){
1975
 
1976
				#串接收件人
1977
				$rcptStr=$rcptStr." --mail-rcpt \"".$mailTo."\"";
1978
 
1979
				}#for end
1980
 
1981
			#初始化允許不安全連線的字串
1982
			$insecure="";
1983
 
1984
			#如果允許不安全的連線
1985
			if($conf["insecure"]==="true"){
1986
 
1987
				#設置允許不安全連線
1988
				$insecure="--insecure";
1989
 
1990
				}#if end
1991
 
1992
			#如果登入帳號不用@
1993
			if($conf["usernameOnly"]==="true"){
1994
 
1995
				#尋找有無 "@"
1996
				$at=strpos($conf["username"],"@");
1997
 
1998
				#如果有找到
1999
				if($at!==false){
2000
 
2001
					#取得不含 @... 的帳戶名稱
2002
					$conf["username"]=substr($conf["username"],0,$at);
2003
 
2004
					}#if end
2005
 
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";
2010
 
2011
			#取得寄信的指令
2012
			$mailCmdArray[]=$cmdString;		
2013
 
2014
			#取得移除信件檔案的指令
2015
			$delMailFileCmd[]="rm \"".$mailFile."\"";
2016
 
2017
			#清空 $mailFileHeader
2018
			$mailFileHeader="";
2019
 
2020
			}#for end	
2021
 
2022
		#用curl寄送信件
2023
		#函式說明:
2024
		#運用nohup與&來達到雖依序執行但不等待前一個指令執行完再執行下一個指令,形成假多工的執行每個指令.
2025
		#回傳結果: 
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__的內容.
2035
		$conf["external::multiThreadsShell"]["fileArgu"]=$conf["fileArgu"];		
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"]);
2051
 
2052
		#如果寄信失敗
2053
		if($multiThreadsShell["status"]=="false")
2054
		{
2055
			#設置錯誤識別
2056
			$result["status"]="false";
2057
 
2058
			#設置錯誤資訊
2059
			$result["error"]=$multiThreadsShell;
2060
 
2061
			#回傳結果
2062
			return $result;
2063
		}
2064
 
2065
		#取得執行的指令
2066
		$result["cmd"]=$multiThreadsShell["cmd"];
2067
 
2068
		/*
2069
 
2070
		#移除信件檔案
2071
		#函式說明:
2072
		#運用nohup與&來達到雖依序執行但不等待前一個指令執行完再執行下一個指令,形成假多工的執行每個指令.
2073
		#回傳結果: 
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__的內容.
2083
		$conf["external::multiThreadsShell"]["fileArgu"]=$conf["fileArgu"];		
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"]);
2099
 
2100
		#如果移除信件檔案失敗
2101
		if($multiThreadsShell["status"]=="false"){
2102
 
2103
			#設置錯誤識別
2104
			$result["status"]="false";
2105
 
2106
			#設置錯誤資訊
2107
			$result["error"]=$multiThreadsShell;
2108
 
2109
			#回傳結果
2110
			return $result;
2111
 
2112
			}
2113
 
2114
		*/			
2115
 
2116
		#設置執行正常
2117
		$result["status"]="true";
2118
 
2119
		#回傳結果
2120
		return $result;
2121
 
2122
		}#function multiCurlSmtp end
2123
 
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"]="";
2138
	#可省略參數: 
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){
2148
 
2149
		#初始化要回傳的結果
2150
		$result=array();
2151
 
2152
		#儲存當前執行的函數
2153
		$result["function"]=__FUNCTION__;
2154
 
2155
		#如果 $conf 不為陣列
2156
		if(gettype($conf)!="array"){
2157
 
2158
			#設置執行失敗
2159
			$result["status"]="false";
2160
 
2161
			#設置執行錯誤訊息
2162
			$result["error"][]="\$conf變數須為陣列形態";
2163
 
2164
			#如果傳入的參數為 null
2165
			if($conf==null){
2166
 
2167
				#設置執行錯誤訊息
2168
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
2169
 
2170
				}#if end
2171
 
2172
			#回傳結果
2173
			return $result;
2174
 
2175
			}#if end
2176
 
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");
2195
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); 
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");
2204
		#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double"); 
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"]);
2214
 
2215
		#如果檢查失敗
2216
		if($checkArguments["status"]=="false"){
2217
 
2218
			#設置錯誤識別
2219
			$result["status"]="false";
2220
 
2221
			#設置錯誤訊息
2222
			$result["error"]=$checkArguments;
2223
 
2224
			#回傳結果
2225
			return $result;
2226
 
2227
			}#if end
2228
 
2229
		#如果檢查不通過
2230
		if($checkArguments["passed"]=="false"){
2231
 
2232
			#設置錯誤識別
2233
			$result["status"]="false";
2234
 
2235
			#設置錯誤訊息
2236
			$result["error"]=$checkArguments;
2237
 
2238
			#回傳結果
2239
			return $result;
2240
 
2241
			}#if end
2242
 
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"]);
2265
 
2266
		#如果檢查失敗
2267
		if($arrayToString["status"]=="false"){
2268
 
2269
			#設置錯誤識別
2270
			$result["status"]="false";
2271
 
2272
			#設置錯誤訊息
2273
			$result["error"]=$arrayToString;
2274
 
2275
			#回傳結果
2276
			return $result;
2277
 
2278
			}#if end
2279
 
2280
		$to = $arrayToString["content"];
2281
		$subject = $conf["subject"];
2282
		$message = $conf["content"];
2283
 
2284
		# In case any of our lines are larger than 70 characters, we should use wordwrap()
2285
		$message = wordwrap($message, 70, "\r\n");
2286
 
2287
		#初始化mail header為空
2288
		$headers = "";
2289
 
2290
		#如果有設置寄件人資訊
2291
		if(isset($conf["mailerEmail"])){
2292
 
2293
			#設置寄件人資訊
2294
			$headers = "From: ".$conf["mailerEmail"];
2295
 
2296
			}#if end
2297
 
2298
		#寄信
2299
		$mailResult=mail($to, $subject, $message, $headers);
2300
 
2301
		#初始化執行正常
2302
		$result["status"]="true";	
2303
 
2304
		#如果寄信失敗
2305
		if(!$mailResult){
2306
 
2307
			#設置執行不正常
2308
			$result["status"]="false";
2309
 
2310
			#回傳結果
2311
			return $result;
2312
 
2313
			}#if end
2314
 
2315
		#回傳結果
2316
		return $result;	
2317
 
2318
		}#function sendMail end
2319
 
2320
	}#class mail end
2321
 
2322
?>