Subversion Repositories php-qbpwcf

Rev

Rev 30 | Go to most recent revision | Details | 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.
6
    Copyright (C) 2015~2024 Min-Jhin,Chen
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
		#無.
1105
		$createTempFile=fileAccess::createTempFile();
1106
 
1107
		#如果檔案建立失敗
1108
		if($createTempFile["status"]=="false"){
1109
 
1110
			#設置錯誤識別
1111
			$result["status"]="false";
1112
 
1113
			#設置錯誤資訊
1114
			$result["error"]=$createTempFile;
1115
 
1116
			#回傳結果
1117
			return $result;
1118
 
1119
			}#if end
1120
 
1121
		#取得要寄送的郵件檔案
1122
		$mailFile=$createTempFile["content"];
1123
 
1124
		#將字串寫入到檔案
1125
		#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
1126
		#$result["error"],錯誤訊息陣列.
1127
		#必填參數:
1128
		$conf["fileAccess::writeTextIntoFile"]["fileName"]=$mailFile;#爲要編輯的檔案名稱
1129
		$conf["fileAccess::writeTextIntoFile"]["inputString"]=$mailFileHeader.$mailFileContent;#爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可。
1130
		$conf["fileAccess::writeTextIntoFile"]["fileArgu"]=$conf["fileArgu"];
1131
		#可省略參數:
1132
		#$conf["writeMethod"]="a";#爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入。
1133
		#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
1134
		$conf["fileAccess::writeTextIntoFile"]["web"]="false";
1135
		$writeTextIntoFile=fileAccess::writeTextIntoFile($conf["fileAccess::writeTextIntoFile"]);
1136
		unset($conf["fileAccess::writeTextIntoFile"]);
1137
 
1138
		#如果檔案建立失敗
1139
		if($writeTextIntoFile["status"]=="false"){
1140
 
1141
			#設置錯誤識別
1142
			$result["status"]="false";
1143
 
1144
			#設置錯誤資訊
1145
			$result["error"]=$writeTextIntoFile;
1146
 
1147
			#回傳結果
1148
			return $result;
1149
 
1150
			}#if end
1151
 
1152
		#要執行的系統命令
1153
		$paramArray=array();
1154
 
1155
		#設置要用 ssl
1156
		$paramArray[]="--ssl-reqd";
1157
 
1158
		#如果為 "levelForCheckSSL" 為 "none"
1159
		if($conf["levelForCheckSSL"]==="none"){
1160
 
1161
			#設置不用確認ssl符合規範
1162
			$paramArray[]="-k";
1163
 
1164
			}#if end
1165
 
1166
		#設置要設定url
1167
		$paramArray[]="--url";
1168
 
1169
		#設置smtp server
1170
		$paramArray[]=$conf["mailServer"];
1171
 
1172
		#設置指定使用者名稱
1173
		$paramArray[]="-u";
1174
 
1175
		#設置使用名稱與密碼
1176
		$paramArray[]=$conf["username"].":".$conf["password"];
1177
 
1178
		#設置要指定寄信來源顯示的名稱
1179
		$paramArray[]="--mail-from";
1180
 
1181
		#設置寄信來源顯示的名稱
1182
		$paramArray[]=$conf["mailerMailDisplay"];
1183
 
1184
		#有幾個收件人就執行幾次
1185
		foreach($conf["receiverMail"] as $mailTo){
1186
 
1187
			#指定收件人的參數
1188
			$paramArray[]="--mail-rcpt";
1189
 
1190
			#串接收件人
1191
			$paramArray[]=$mailTo;
1192
 
1193
			}#for end
1194
 
1195
		#指定mail檔案
1196
		$paramArray[]="--upload-file";
1197
		$paramArray[]=$mailFile;
1198
 
1199
		#看過程
1200
		$paramArray[]="-v";
1201
 
1202
		#用curl寄送信件
1203
		#函式說明:
1204
		#呼叫shell執行系統命令,並取得回傳的內容.
1205
		#回傳的結果:
1206
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1207
		#$result["error"],錯誤訊息陣列.
1208
		#$result["function"],當前執行的函數名稱.
1209
		#$result["cmd"],執行的指令內容.
1210
		#$result["output"],爲執行完二元碼後的輸出陣列.
1211
		#必填參數:
1212
		$conf["external::callShell"]["command"]="curl";#要執行的指令與參
1213
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
1214
		#可省略參數:
1215
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
1216
		$conf["external::callShell"]["argu"]=$paramArray;
1217
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
1218
		#$conf["enablePrintDescription"]="true";
1219
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
1220
		#$conf["printDescription"]="";
1221
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
1222
		$conf["external::callShell"]["escapeshellarg"]="true";
1223
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行apache的使用者,該參數不適用於apache環境.
1224
		#$conf["username"]="";
1225
		#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
1226
		#$conf["password"]="";
1227
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要;"false"代表不要,預設為"false".
1228
		#$conf["useScript"]="";
1229
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 ".qbpwcf_tmp/external/callShell/".
1230
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
1231
		#$conf["fileArgu"],字串,變數__FILE__的內容,預設為當前檔案的路徑與名稱.
1232
		#$conf["fileArgu"]=""; 
1233
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false".
1234
		#$conf["external::callShell"]["inBackGround"]="true";
1235
		#參考資料:
1236
		#http://php.net/manual/en/function.exec.php
1237
		$external["callShell"]=external::callShell($conf["external::callShell"]);
1238
		unset($conf["external::callShell"]);
1239
 
1240
		#如果 $external["callShell"] 等於 "false"
1241
		if($external["callShell"]["status"]==="false"){
1242
 
1243
			#如果 "levelForCheckSSL" 為 "loose"
1244
			if($conf["levelForCheckSSL"]==="loose"){
1245
 
1246
				#加上 "-k" 參數,這次不用符合ssl規範
1247
				$paramArray[]="-k";
1248
 
1249
				#用curl寄送信件
1250
				#函式說明:
1251
				#呼叫shell執行系統命令,並取得回傳的內容.
1252
				#回傳的結果:
1253
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1254
				#$result["error"],錯誤訊息陣列.
1255
				#$result["function"],當前執行的函數名稱.
1256
				#$result["cmd"],執行的指令內容.
1257
				#$result["output"],爲執行完二元碼後的輸出陣列.
1258
				#必填參數:
1259
				$conf["external::callShell"]["command"]="curl";#要執行的指令與參
1260
				$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
1261
				#可省略參數:
1262
				#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
1263
				$conf["external::callShell"]["argu"]=$paramArray;
1264
				#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
1265
				#$conf["enablePrintDescription"]="true";
1266
				#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
1267
				#$conf["printDescription"]="";
1268
				#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
1269
				$conf["external::callShell"]["escapeshellarg"]="true";
1270
				#$conf["username"],字串,要用什麼使用者來執行,預設為執行apache的使用者,該參數不適用於apache環境.
1271
				#$conf["username"]="";
1272
				#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
1273
				#$conf["password"]="";
1274
				#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要;"false"代表不要,預設為"false".
1275
				#$conf["useScript"]="";
1276
				#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 ".qbpwcf_tmp/external/callShell/".
1277
				#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
1278
				#$conf["fileArgu"],字串,變數__FILE__的內容,預設為當前檔案的路徑與名稱.
1279
				#$conf["fileArgu"]=""; 
1280
				#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false".
1281
				#$conf["external::callShell"]["inBackGround"]="true";
1282
				#參考資料:
1283
				#http://php.net/manual/en/function.exec.php
1284
				$external["callShell"]=external::callShell($conf["external::callShell"]);
1285
				unset($conf["external::callShell"]);
1286
 
1287
				#如果 $external["callShell"] 等於 "false"
1288
				if($external["callShell"]["status"]==="false"){
1289
 
1290
					#設置錯誤識別
1291
					$result["status"]="false";
1292
 
1293
					#設置錯誤訊息
1294
					$result["error"]=$external["callShell"];
1295
 
1296
					#回傳結果
1297
					return $result;
1298
 
1299
					}#if end
1300
 
1301
				}#if end
1302
 
1303
			#反之
1304
			else{
1305
 
1306
				#設置錯誤識別
1307
				$result["status"]="false";
1308
 
1309
				#設置錯誤訊息
1310
				$result["error"]=$external["callShell"];
1311
 
1312
				#回傳結果
1313
				return $result;
1314
 
1315
				}#else end`
1316
 
1317
			}#if end
1318
 
1319
		#取得較完整的指令
1320
		$result["cmd"]=$external["callShell"]["cmd"];
1321
 
1322
		#移除信件檔案
1323
		#函式說明:
1324
		#移除檔案
1325
		#回傳結果:
1326
		#$result["status"],"true"代表移除成功,"false"代表移除失敗.
1327
		#$result["error"],錯誤訊息陣列
1328
		#$result["warning"],警告訊息陣列
1329
		#$result["function"],當前執行的函數名稱
1330
		#必填參數:
1331
		$conf["fileAccess::delFile"]["fileAddress"]=$mailFile;#要移除檔案的位置
1332
		$conf["fileAccess::delFile"]["fileArgu"]=$conf["fileArgu"];
1333
		$delMailFile=fileAccess::delFile($conf["fileAccess::delFile"]);
1334
		unset($conf["fileAccess::delFile"]);
1335
 
1336
		#如果移除信件檔案失敗
1337
		if($delMailFile["status"]==="false"){
1338
 
1339
			#設置錯誤識別
1340
			$result["status"]="false";
1341
 
1342
			#設置錯誤訊息
1343
			$result["error"]=$delMailFile;
1344
 
1345
			#回傳結果
1346
			return $result;
1347
 
1348
			}#if end
1349
 
1350
		#可以執行到這邊,就表示十之八九寄信成功了
1351
		$result["status"]="true";
1352
 
1353
		#回傳結果
1354
		return $result;
1355
 
1356
		}#function curlSmtp end
1357
 
1358
	/*
1359
	#函式說明:
1360
	#使用 linux 的 curl 指令來透過SMTP伺服器寄大量不同內容的信件.
1361
	#回傳結果:
1362
	#$result["status"],寄信的情況,若爲"true",則十之八九沒有問題.
1363
	#$result["error"],錯誤訊息陣列
1364
	#$result["function"],當前執行的函數
1365
	#$result["warning"],警示訊息,一些不會導致失敗但不能說是完美的問題.
1366
	#$result["cmd"],寄信的指令.
1367
	#$result["detailCmd"],較詳細的寄信指令.
1368
	#必填參數:
1369
	#$conf["username"],字串,用來登入郵件伺服器的帳號
1370
	$conf["username"]="";
1371
	#$conf["password"],字串,用來登入郵件伺服器的密碼
1372
	$conf["password"]="";
1373
	#$conf["receiverMail"],二維字串陣列,每個信件的收件人信箱有哪些.
1374
	$conf["receiverMail"]=array(array());
1375
	#$conf["subject"],字串陣列,每封郵件的主題.
1376
	$conf["subject"]=array("");
1377
	#$conf["plainBody"],字串陣列,郵件本文的純文字內容.
1378
	$conf["plainBody"]=array("");
1379
	#$conf["htmlBody"]="";,字串陣列,郵件本文的html內容,多媒體盡量不要用base64的方式來嵌入,因為大部分的郵件服務(Gmail)都不支援,如果是在單機上的郵件軟體就可能有支援,例如:Evolution.
1380
	$conf["htmlBody"]=array("");
1381
	#$conf["fileArgu"],字串,php內建變數「__FILE__」的內容.
1382
	$conf["fileArgu"]=__FILE__;
1383
	#可省略參數:
1384
	#$conf["usernameOnly"],字串,登入的帳號是否只要名稱不要@,預設爲"false"使用完整名稱跟@;反之爲"false".
1385
	#$conf["usernameOnly"]="false";
1386
	#$conf["mailServer"],字串,要使用的SMTP郵件伺服器網址與連接口,預設爲 smtps://smtp.gmail.com:465
1387
	#$conf["mailServer"]="";
1388
	#$conf["mailerMailDisplay"],字串,要顯示的寄件人信箱,預設爲 $conf["username"]
1389
	#$conf["mailerMailDisplay"]="";
1390
	#$conf["mailerNameDisplay"],字串,要顯示的寄件人姓名,預設爲 $conf["username"]
1391
	#$conf["mailerNameDisplay"]="";
1392
	#$conf["receiverMailDisplay"],陣列,每封信要顯示的收件人信箱,預設爲 $conf["receiverMail"] 對應的元素.
1393
	#$conf["receiverMailDisplay"]=array("");
1394
	#$conf["receiverNameDisplay"],陣列,每封信要顯示的收件人姓名,預設爲 $conf["receiverMail"] 對應的元素.
1395
	#$conf["receiverNameDisplay"]=array("");
1396
	#$conf["attachment"],二維陣列,每個信件要寄送的附件路徑與檔案名稱
1397
	#$conf["attachment"]=array(array());
1398
	#$conf["attachmentName"],二維陣列,每個信件要寄送的附件顯示名稱,預設為$conf["attachment"]中的實際檔案名稱.
1399
	#$conf["attachmentName"]=array(array());
1400
	#$conf["attachmentMimeType"],二維陣列,每個信件附件的 mimeType,預設為"application/*".
1401
	#$conf["attachmentMimeType"]array(array());
1402
	#$conf["insecure"],字串,是否允許不安全的tls連線,預設爲"false"不允許,"true"爲允許.
1403
	#$conf["insecure"]="false";
1404
	#參考資料:
1405
	#無.
1406
	#備註:
1407
	#無.
1408
	*/
1409
	public static function multiCurlSmtp(&$conf){
1410
 
1411
		#初始化要回傳的結果
1412
		$result=array();
1413
 
1414
		#儲存當前執行的函數
1415
		$result["function"]=__FUNCTION__;
1416
 
1417
		#如果 $conf 不為陣列
1418
		if(gettype($conf)!="array"){
1419
 
1420
			#設置執行失敗
1421
			$result["status"]="false";
1422
 
1423
			#設置執行錯誤訊息
1424
			$result["error"][]="\$conf變數須為陣列形態";
1425
 
1426
			#如果傳入的參數為 null
1427
			if($conf==null){
1428
 
1429
				#設置執行錯誤訊息
1430
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
1431
 
1432
				}#if end
1433
 
1434
			#回傳結果
1435
			return $result;
1436
 
1437
			}#if end
1438
 
1439
		#檢查參數
1440
		#函式說明:
1441
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
1442
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1443
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
1444
		#$result["function"],當前執行的函式名稱.
1445
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
1446
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
1447
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
1448
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
1449
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
1450
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
1451
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
1452
		#必填寫的參數:
1453
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
1454
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
1455
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
1456
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("username","password","receiverMail","subject","plainBody","htmlBody","fileArgu");
1457
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); 
1458
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","array","array","array","array","string");
1459
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
1460
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
1461
		#可以省略的參數:
1462
		#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
1463
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
1464
		#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
1465
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("attachment","attachmentName","attachmentMimeType","mailServer","mailerMailDisplay","mailerNameDisplay","receiverMailDisplay","receiverNameDisplay","insecure","usernameOnly");
1466
		#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double"); 
1467
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array","array","array","string","string","string","array","array","string","string");
1468
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
1469
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,null,null,"smtps://smtp.gmail.com:465","\$conf[\"username\"]","\$conf[\"username\"]","\$conf[\"receiverMail\"]","\$conf[\"receiverMail\"]","false","false");
1470
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
1471
		$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("subject","plainBody","htmlBody","receiverMail","receiverMailDisplay","receiverNameDisplay");
1472
		#參考資料來源:
1473
		#array_keys=>http://php.net/manual/en/function.array-keys.php
1474
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
1475
		unset($conf["variableCheck::checkArguments"]);
1476
 
1477
		#如果檢查失敗
1478
		if($checkArguments["status"]=="false"){
1479
 
1480
			#設置錯誤識別
1481
			$result["status"]="false";
1482
 
1483
			#設置錯誤訊息
1484
			$result["error"]=$checkArguments;
1485
 
1486
			#回傳結果
1487
			return $result;
1488
 
1489
			}#if end
1490
 
1491
		#如果檢查不通過
1492
		if($checkArguments["passed"]=="false"){
1493
 
1494
			#設置錯誤識別
1495
			$result["status"]="false";
1496
 
1497
			#設置錯誤訊息
1498
			$result["error"]=$checkArguments;
1499
 
1500
			#回傳結果
1501
			return $result;
1502
 
1503
			}#if end
1504
 
1505
		#檢查 .curlSmtp 資料夾是否存在
1506
		#函式說明:檢查多個檔案是否存在
1507
		#回傳的結果:
1508
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
1509
		#$result["error"],錯誤訊息陣列.
1510
		#$resutl["function"],當前執行的涵式名稱.
1511
		#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
1512
		#$result["varName"][$i],爲第$i個資料夾或檔案的名稱。
1513
		#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
1514
		#必填參數:
1515
		$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array(".curlSmtp");#要檢查書否存在的檔案有哪些,須爲一維陣列數值。
1516
		$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
1517
		#參考資料來源:
1518
		#http://php.net/manual/en/function.file-exists.php
1519
		#http://php.net/manual/en/control-structures.foreach.php
1520
		$checkMutiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
1521
		unset($conf["fileAccess::checkMultiFileExist"]);
1522
 
1523
		#如果檢查檔案失敗
1524
		if($checkMutiFileExist["status"]=="false"){
1525
 
1526
			#設置錯誤識別
1527
			$result["status"]="false";
1528
 
1529
			#設置錯誤訊息
1530
			$result["error"]=$checkMutiFileExist;
1531
 
1532
			#回傳結果
1533
			return $result;
1534
 
1535
			}#if end
1536
 
1537
		#如果該資料夾不存在
1538
		if($checkMutiFileExist["varExist"][0]=="false"){
1539
 
1540
			#則建立該資料夾
1541
			#函式說明:
1542
			#建立資料夾,若要建立的資料夾所屬路徑不存在,則會自動嘗試建立,建立後的資料夾也可指定權限.
1543
			#回傳結果:
1544
			#$result["status"],"true"爲建立成功,"false"爲建立失敗.
1545
			#$result["error"],錯誤訊息陣列
1546
			#必填參數:
1547
			$conf["fileAccess::createFolderAfterCheck"]["dirPositionAndName"]=".curlSmtp";#新建的位置與名稱
1548
			$conf["fileAccess::createFolderAfterCheck"]["fileArgu"]=$conf["fileArgu"];
1549
			#可省略參數:
1550
			#$conf["fileAccess::createFolderAfterCheck"]["dirPermission"]="";#新建資料夾的權限設定,預設爲0770,亦即擁有者,同群組者可以讀,寫,存取,其他人僅能存取.
1551
			$createFolderAfterCheck=fileAccess::createFolderAfterCheck($conf["fileAccess::createFolderAfterCheck"]);
1552
			unset($conf["fileAccess::createFolderAfterCheck"]);
1553
 
1554
			#如果 建立資料夾失敗
1555
			if($createFolderAfterCheck["status"]=="false"){
1556
 
1557
				#設置錯誤識別
1558
				$result["status"]="false";
1559
 
1560
				#設置錯誤訊息
1561
				$result["errot"]=$createFolderAfterCheck;
1562
 
1563
				#回傳結果
1564
				return $result;
1565
 
1566
				}#if end
1567
 
1568
			}#if end
1569
 
1570
		#初始化寄信的command
1571
		#$mailCmd="";
1572
 
1573
		#初始化寄信的指令
1574
		$mailCmdArray=array();		
1575
 
1576
		#初始化移除信件檔案的指令
1577
		$delMailFileCmd=array();
1578
 
1579
		#取得 $systemTime	
1580
		$systemTime=time::getMicrotime();
1581
 
1582
		#要傳送的信件資訊
1583
		$fromInfo="From: ".$conf["mailerNameDisplay"]." <".$conf["mailerMailDisplay"].">\r\n";
1584
 
1585
		#初始化信件的 header
1586
		$mailFileHeader="";
1587
 
1588
		#依據 $conf["receiverMail"] 的數量
1589
		for($i=0;$i<count($conf["receiverMail"]);$i++){
1590
 
1591
			#串接寄件人的資訊
1592
			$mailFileHeader=$mailFileHeader.$fromInfo;
1593
 
1594
			#如果第$i筆信件的收件人陣列不存在
1595
			if(!isset($conf["receiverMail"][$i])){
1596
 
1597
				#設置執行不正常
1598
				$result["status"]="false";
1599
 
1600
				#設置錯誤訊息
1601
				$result["error"][]="第".($i+1)."筆收件人陣列不存在";
1602
 
1603
				#回傳結果
1604
				return $result;
1605
 
1606
				}#if end
1607
 
1608
			#反之存在但形態不為陣列
1609
			if(gettype($conf["receiverMail"][$i])!="array"){
1610
 
1611
				#設置執行不正常
1612
				$result["status"]="false";
1613
 
1614
				#設置錯誤訊息
1615
				$result["error"][]="第".($i+1)."筆收件人陣列形態不正確";
1616
 
1617
				#回傳結果
1618
				return $result;
1619
 
1620
				}#if end	
1621
 
1622
			#如果第$i筆信件的收件人名稱不存在
1623
			if(!isset($conf["receiverNameDisplay"][$i])){
1624
 
1625
				#設為第$i筆信件的收件人陣列
1626
				$conf["receiverNameDisplay"][$i]=$conf["receiverMail"][$i];
1627
 
1628
				}#if end
1629
 
1630
			#第$i筆信件收件人名稱陣列的第一個元素不存在
1631
			else if(!isset($conf["receiverNameDisplay"][$i][0])){
1632
 
1633
				#設置執行不正常
1634
				$result["status"]="false";
1635
 
1636
				#設置錯誤訊息
1637
				$result["error"][]="第".($i+1)."筆收件人名稱陣列的第一個收件人名稱不存在";
1638
 
1639
				#回傳結果
1640
				return $result;
1641
 
1642
				}#if end
1643
 
1644
			#如果第$i筆信件的收件人信箱名稱不存在
1645
			if(!isset($conf["receiverMailDisplay"][$i])){
1646
 
1647
				#設為第$i筆信件的收件人陣列
1648
				$conf["receiverMailDisplay"][$i]=$conf["receiverMail"][$i];
1649
 
1650
				}#if end
1651
 
1652
			#第$i筆信件收件人信箱名稱陣列的第一個元素不存在
1653
			else if(!isset($conf["receiverNameDisplay"][$i][0])){
1654
 
1655
				#設置執行不正常
1656
				$result["status"]="false";
1657
 
1658
				#設置錯誤訊息
1659
				$result["error"][]="第".($i+1)."筆收件人信箱名稱陣列的第一個收件人信箱名稱不存在";
1660
 
1661
				#回傳結果
1662
				return $result;
1663
 
1664
				}#if end						
1665
 
1666
			#第一個人為主要收件人
1667
			$mailFileHeader=$mailFileHeader."To: ".$conf["receiverNameDisplay"][$i][0]." "."<".$conf["receiverMailDisplay"][$i][0].">\r\n";			
1668
 
1669
			#如果有其餘收件人
1670
			if(count($conf["receiverNameDisplay"][$i])>1){
1671
 
1672
				#副本寄送處的資訊開始
1673
				$mailFileHeader=$mailFileHeader."Cc: ";
1674
 
1675
				}#if end
1676
 
1677
			#針對其餘收件人的地址
1678
			for($j=1;$j<count($conf["receiverNameDisplay"][$i]);$j++){
1679
 
1680
				#如果不是最後一筆
1681
				if($j!=count($conf["receiverNameDisplay"][$i])-1){
1682
 
1683
					#串接並加上逗號
1684
					$mailFileHeader=$mailFileHeader.$conf["receiverNameDisplay"][$i][$j]." <".$conf["receiverMailDisplay"][$i][$j].">,";
1685
 
1686
					}#if end
1687
 
1688
				#反之是最後一筆
1689
				else{
1690
 
1691
					#串接並接上換行符號
1692
					$mailFileHeader=$mailFileHeader.$conf["receiverNameDisplay"][$i][$j]." <".$conf["receiverMailDisplay"][$i][$j].">\r\n";
1693
 
1694
					}#else end				
1695
 
1696
				}#for end
1697
 
1698
			#設置信件標題
1699
			$mailFileHeader=$mailFileHeader."Subject: ".$conf["subject"][$i]."\r\n";
1700
 
1701
			#設置 MIME-Version
1702
			$mailFileHeader=$mailFileHeader."MIME-Version: 1.0\r\n";
1703
 
1704
			#初始化信件本文
1705
			$mailFileContent="";
1706
 
1707
			#設置信件本文(純文字與html兩種)				
1708
			$mailFileContent=$mailFileContent."--001a11c30ce8aec3550533bfa9ab\r\n";
1709
			$mailFileContent=$mailFileContent."Content-Type: multipart/alternative; boundary=001a11c30ce8aec3480533bfa9a9\r\n";
1710
			$mailFileContent=$mailFileContent."\r\n";
1711
			$mailFileContent=$mailFileContent."--001a11c30ce8aec3480533bfa9a9\r\n";
1712
			$mailFileContent=$mailFileContent."Content-Type: text/plain; charset=UTF-8\r\n";
1713
			$mailFileContent=$mailFileContent."\r\n";
1714
			$mailFileContent=$mailFileContent.$conf["plainBody"][$i]."\r\n";
1715
			$mailFileContent=$mailFileContent."\r\n";
1716
			$mailFileContent=$mailFileContent."--001a11c30ce8aec3480533bfa9a9\r\n";
1717
			$mailFileContent=$mailFileContent."Content-Type: text/html; charset=UTF-8\r\n";
1718
			$mailFileContent=$mailFileContent."\r\n";
1719
			$mailFileContent=$mailFileContent.$conf["htmlBody"][$i]."\r\n";
1720
			$mailFileContent=$mailFileContent."\r\n";
1721
			$mailFileContent=$mailFileContent."--001a11c30ce8aec3480533bfa9a9--\r\n";
1722
 
1723
			#如果有設定要上傳附件
1724
			if(isset($conf["attachment"])){
1725
 
1726
				#如果第 $i+1 封信件有指定 附件
1727
				if(isset($conf["attachment"][$i])){
1728
 
1729
					#如果類型正確
1730
					if(gettype($conf["attachment"][$i])=="array"){
1731
 
1732
						#依據每個附件
1733
						for($j=0;$j<count($conf["attachment"][$i]);$j++){
1734
 
1735
							#初始化寄送附件的語法
1736
							$attachment="";
1737
 
1738
							#確認目標檔案是否存在 #函式說明:檢查多個檔案是否存在 #回傳的結果: 
1739
							#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常. 
1740
							#$result["error"],錯誤訊息陣列. 
1741
							#$resutl["function"],當前執行的涵式名稱. 
1742
							#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在. 
1743
							#$result["varName"][$i],爲第$i個資料夾或檔案的名稱。 
1744
							#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。 
1745
							#必填參數: 
1746
							$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"]; 
1747
							$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($conf["attachment"][$i][$j]);#要檢查書否存在的檔案有哪些,須爲一維陣列數值。 
1748
							#參考資料來源: 
1749
							#http://php.net/manual/en/function.file-exists.php 
1750
							#http://php.net/manual/en/control-structures.foreach.php 
1751
							$checkMutiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]); 
1752
							unset($conf["fileAccess::checkMultiFileExist"]);
1753
 
1754
							#如果檢查失敗
1755
							if($checkMutiFileExist["status"]=="false"){
1756
 
1757
								#設置錯誤識別
1758
								$result["status"]="false";
1759
 
1760
								#設置錯誤資訊
1761
								$result["error"]=$checkMutiFileExist;
1762
 
1763
								#回傳結果
1764
								return $result;
1765
 
1766
								}#if end
1767
 
1768
							#如果檔案不存在
1769
							if($checkMutiFileExist["varExist"][0]=="false"){
1770
 
1771
								#設置錯誤識別
1772
								$result["status"]="false";
1773
 
1774
								#設置錯誤資訊
1775
								$result["error"]=$checkMutiFileExist;
1776
 
1777
								#回傳結果
1778
								return $result;
1779
 
1780
								}#if end
1781
 
1782
							#如果是第一個附件
1783
							if($j==0){
1784
 
1785
								#在前面加上 multipart/mixed 的 boundary
1786
								$mailFileContent="Content-Type: multipart/mixed; boundary=001a11c30ce8aec3550533bfa9ab\r\n\r\n".$mailFileContent;
1787
 
1788
								}#if end
1789
 
1790
							#如果 $conf["attachmentName"][$i] 不存在
1791
							if(!isset($conf["attachmentName"][$i])){
1792
 
1793
								#涵是說明:
1794
								#取得檔案路徑字串的路徑與檔案的名稱與檔案副檔名
1795
								#回傳的結果:
1796
								#$result["status"],執行是否正常,"true"正常,"false"代表不正常.
1797
								#$result["error"],錯誤訊息.
1798
								#$result["function"],當前執行的函式名稱.
1799
								#$result["filePath"],路徑字串.
1800
								#$result["fileName"],檔案名稱字串.
1801
								#$result["fileExtention"],檔案的副檔名.
1802
								#$result["fullFileName"],含副檔名的檔案名稱.
1803
								#$result["fullFilePathAndName"],完整的檔案路徑(含副檔名).
1804
								#必填參數:
1805
								#$conf["fileAddressAndName"],字串,檔案名稱與其路徑.
1806
								$conf["fileAccess::getFileAddressAndNameAndFileExtention"]["fileAddressAndName"]=$conf["attachment"][$i][$j];
1807
								#可省略的參數:
1808
								#無.
1809
								$getFileAddressAndNameAndFileExtention=fileAccess::getFileAddressAndNameAndFileExtention($conf["fileAccess::getFileAddressAndNameAndFileExtention"]);
1810
								unset($conf["fileAccess::getFileAddressAndNameAndFileExtention"]);
1811
 
1812
								#如果解析檔案資訊失敗		
1813
								if($getFileAddressAndNameAndFileExtention["status"]=="false"){
1814
 
1815
									#設置錯誤識別
1816
									$result["status"]="false";
1817
 
1818
									#設置錯誤資訊
1819
									$result["error"]=$getFileAddressAndNameAndFileExtention;
1820
 
1821
									#回傳結果
1822
									return $result;
1823
 
1824
									}#if end			
1825
 
1826
								#設定附件名稱
1827
								$conf["attachmentName"][$i][$j]=$getFileAddressAndNameAndFileExtention["fullFileName"];
1828
 
1829
								}#if end
1830
 
1831
							#反之如果 $conf["attachmentName"][$i][$j] 不存在
1832
							else if(!isset($conf["attachmentName"][$i][$j])){
1833
 
1834
								#涵是說明:
1835
								#取得檔案路徑字串的路徑與檔案的名稱與檔案副檔名
1836
								#回傳的結果:
1837
								#$result["status"],執行是否正常,"true"正常,"false"代表不正常.
1838
								#$result["error"],錯誤訊息.
1839
								#$result["function"],當前執行的函式名稱.
1840
								#$result["filePath"],路徑字串.
1841
								#$result["fileName"],檔案名稱字串.
1842
								#$result["fileExtention"],檔案的副檔名.
1843
								#$result["fullFileName"],含副檔名的檔案名稱.
1844
								#$result["fullFilePathAndName"],完整的檔案路徑(含副檔名).
1845
								#必填參數:
1846
								#$conf["fileAddressAndName"],字串,檔案名稱與其路徑.
1847
								$conf["fileAccess::getFileAddressAndNameAndFileExtention"]["fileAddressAndName"]=$conf["attachment"][$i][$j];
1848
								#可省略的參數:
1849
								#無.
1850
								$getFileAddressAndNameAndFileExtention=fileAccess::getFileAddressAndNameAndFileExtention($conf["fileAccess::getFileAddressAndNameAndFileExtention"]);
1851
								unset($conf["fileAccess::getFileAddressAndNameAndFileExtention"]);
1852
 
1853
								#如果解析檔案資訊失敗		
1854
								if($getFileAddressAndNameAndFileExtention["status"]=="false"){
1855
 
1856
									#設置錯誤識別
1857
									$result["status"]="false";
1858
 
1859
									#設置錯誤資訊
1860
									$result["error"]=$getFileAddressAndNameAndFileExtention;
1861
 
1862
									#回傳結果
1863
									return $result;
1864
 
1865
									}#if end			
1866
 
1867
								#設定附件名稱
1868
								$conf["attachmentName"][$i][$j]=$getFileAddressAndNameAndFileExtention["fullFileName"];
1869
 
1870
								}#if end
1871
 
1872
							#如果 $conf["attachmentMimeType"][$i][$j] 不存在
1873
							if(!isset($conf["attachmentMimeType"][$i])){
1874
 
1875
								#設定檔案類型
1876
								$conf["attachmentMimeType"][$i][$j]="application/*";
1877
 
1878
								}#if end	
1879
 
1880
							#反之如果 $conf["attachmentMimeType"][$i][$j] 不存在	
1881
							else if(!isset($conf["attachmentMimeType"][$i][$j])){
1882
 
1883
								$conf["attachmentMimeType"][$i][$j]="application/*";
1884
 
1885
								}#if end
1886
 
1887
							#加上寄送附件的語法
1888
							$attachment=$attachment."--001a11c30ce8aec3550533bfa9ab\r\n";
1889
							$attachment=$attachment."Content-Type: ".$conf["attachmentMimeType"][$i][$j]."; name=".$conf["attachmentName"][$i][$j]."\r\n";
1890
							$attachment=$attachment."Content-Disposition: attachment; filename=".$conf["attachmentName"][$i][$j]."\r\n";
1891
							$attachment=$attachment."Content-Transfer-Encoding: base64\r\n";			
1892
							$attachment=$attachment."X-Attachment-Id: f_io1ikfii".$i."_".$j."\r\n";
1893
 
1894
							#將檔案用base64加密					
1895
							$base64fileStr=base64_encode(file_get_contents($conf["attachment"][$i][$j]));
1896
 
1897
							#依據規定,每列不得大於70的字元
1898
							$wordwrapedFileStr=wordwrap($base64fileStr,70,"\r\n",true);
1899
 
1900
							#斷行後附加檔案字串
1901
							$attachment=$attachment."\r\n".$wordwrapedFileStr."\r\n";	
1902
 
1903
							#如果是最後一個附件
1904
							if($j==count($conf["attachment"][$i])-1){
1905
 
1906
								#混合資料結尾
1907
								$attachment=$attachment."--001a11c30ce8aec3550533bfa9ab--\r\n";
1908
 
1909
								}#if end	
1910
 
1911
							#增加到信件內文的結尾
1912
							$mailFileContent=$mailFileContent.$attachment;
1913
 
1914
							}#for end
1915
 
1916
						}#if end
1917
 
1918
					}#if end
1919
 
1920
				}#if end
1921
 
1922
			#要寄送的郵件檔案路徑與名稱
1923
			$mailFile=".curlSmtp/mail_at_".$systemTime.".mail";	
1924
 
1925
			#建立要寄送的郵件檔案
1926
			#將字串寫入到檔案
1927
			#回傳結果:
1928
			#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
1929
			#$result["error"],錯誤訊息陣列.
1930
			#$result["function"],當前執行的函數名稱.
1931
			#$result["fileInfo"],實際上寫入的檔案資訊陣列.
1932
			#$result["fileInfo"]["createdFileName"],建立好的檔案名稱.
1933
			#$result["fileInfo"]["createdFilePath"],檔案建立的路徑.
1934
			#$result["fileInfo"]["createdFilePathAndName"].建立好的檔案名稱與路徑.
1935
			#必填參數:
1936
			$conf["fileAccess::writeTextIntoFile"]["fileName"]=$mailFile;#爲要編輯的檔案名稱
1937
			$conf["fileAccess::writeTextIntoFile"]["inputString"]=$mailFileHeader.$mailFileContent;#爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可。
1938
			$conf["fileAccess::writeTextIntoFile"]["fileArgu"]=$conf["fileArgu"];
1939
			#可省略參數:
1940
			#$conf["writeMethod"],字串,爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入.
1941
			#$conf["writeMethod"]="a";
1942
			#$conf["checkRepeat"],字串,"true"代表建立檔案之前要先檢查檔案是否存在,若存在則在原名稱後面加上從(1)開始的編號.
1943
			$conf["fileAccess::writeTextIntoFile"]["checkRepeat"]="true";
1944
			#$conf["filenameExtensionStartPoint"],字串,檔案的副檔名是從倒數第幾個小數點(dot)開始,預設為"1",最後一個小數點
1945
			#$conf["filenameExtensionStartPoint"]="";
1946
			#$conf["repeatNameRule"],字串,遇到相同名稱的檔案要如何加上識別的編號,編號用「\$i」表示,預設為"(\$i)"
1947
			$conf["fileAccess::writeTextIntoFile"]["repeatNameRule"]="_\$i";
1948
			$writeTextIntoFile=fileAccess::writeTextIntoFile($conf["fileAccess::writeTextIntoFile"]);
1949
			unset($conf["fileAccess::writeTextIntoFile"]);
1950
 
1951
			#如果檔案建立失敗
1952
			if($writeTextIntoFile["status"]=="false"){
1953
 
1954
				#設置錯誤識別
1955
				$result["status"]="false";
1956
 
1957
				#設置錯誤資訊
1958
				$result["error"]=$writeTextIntoFile;
1959
 
1960
				#回傳結果
1961
				return $result;
1962
 
1963
				}#if end
1964
 
1965
			#取得建立好的檔案名稱
1966
			$mailFile=$writeTextIntoFile["fileInfo"]["createdFilePathAndName"];
1967
 
1968
			#初始化收件人字串
1969
			$rcptStr="";
1970
 
1971
			#有幾個收件人就執行幾次
1972
			foreach($conf["receiverMail"][$i] as $mailTo){
1973
 
1974
				#串接收件人
1975
				$rcptStr=$rcptStr." --mail-rcpt \"".$mailTo."\"";
1976
 
1977
				}#for end
1978
 
1979
			#初始化允許不安全連線的字串
1980
			$insecure="";
1981
 
1982
			#如果允許不安全的連線
1983
			if($conf["insecure"]==="true"){
1984
 
1985
				#設置允許不安全連線
1986
				$insecure="--insecure";
1987
 
1988
				}#if end
1989
 
1990
			#如果登入帳號不用@
1991
			if($conf["usernameOnly"]==="true"){
1992
 
1993
				#尋找有無 "@"
1994
				$at=strpos($conf["username"],"@");
1995
 
1996
				#如果有找到
1997
				if($at!==false){
1998
 
1999
					#取得不含 @... 的帳戶名稱
2000
					$conf["username"]=substr($conf["username"],0,$at);
2001
 
2002
					}#if end
2003
 
2004
				}#if end
2005
 
2006
			#設置要執行的系統命令(寄信)
2007
			$cmdString="curl --ssl --anyauth -1 ".$insecure." --url \"".$conf["mailServer"]."\" -u \"".$conf["username"].":".$conf["password"]."\" --mail-from \"".$conf["mailerMailDisplay"]."\" $rcptStr --upload-file \"".$mailFile."\" -v";
2008
 
2009
			#取得寄信的指令
2010
			$mailCmdArray[]=$cmdString;		
2011
 
2012
			#取得移除信件檔案的指令
2013
			$delMailFileCmd[]="rm \"".$mailFile."\"";
2014
 
2015
			#清空 $mailFileHeader
2016
			$mailFileHeader="";
2017
 
2018
			}#for end	
2019
 
2020
		#用curl寄送信件
2021
		#函式說明:
2022
		#運用nohup與&來達到雖依序執行但不等待前一個指令執行完再執行下一個指令,形成假多工的執行每個指令.
2023
		#回傳結果: 
2024
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2025
		#$result["error"],錯誤訊息陣列.
2026
		#$result["function"],當前執行的函數名稱.
2027
		#$result["cmd"],執行的指令內容.
2028
		#$result["output"],爲執行完二元碼後的輸出陣列.
2029
		#必填參數:
2030
		#$conf["command"],字串陣列,要執行的指令與.
2031
		$conf["external::multiThreadsShell"]["command"]=$mailCmdArray;
2032
		#$conf["fileArgu"],字串,變數__FILE__的內容.
2033
		$conf["external::multiThreadsShell"]["fileArgu"]=$conf["fileArgu"];		
2034
		#可省略參數:
2035
		#$conf["argu"],二維陣列字串,每個指令搭配的參數,預設為空陣列.
2036
		#$conf["argu"]=array(array());
2037
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
2038
		#$conf["enablePrintDescription"]="true";
2039
		#$conf["printDescription"],字串陣列,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
2040
		#$conf["printDescription"]=array("");
2041
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
2042
		#$conf["escapeshellarg"]="false";
2043
		#$conf["username"],字串陣列,每個指令要用什麼使用者來執行,預設為執行php使用者,該參數不適用於apache環境.
2044
		#$conf["username"]=array("");
2045
		#$conf["password"],字串陣列,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
2046
		#$conf["password"]=array("");
2047
		$multiThreadsShell=external::multiThreadsShell($conf["external::multiThreadsShell"]);
2048
		unset($conf["external::multiThreadsShell"]);
2049
 
2050
		#如果寄信失敗
2051
		if($multiThreadsShell["status"]=="false")
2052
		{
2053
			#設置錯誤識別
2054
			$result["status"]="false";
2055
 
2056
			#設置錯誤資訊
2057
			$result["error"]=$multiThreadsShell;
2058
 
2059
			#回傳結果
2060
			return $result;
2061
		}
2062
 
2063
		#取得執行的指令
2064
		$result["cmd"]=$multiThreadsShell["cmd"];
2065
 
2066
		/*
2067
 
2068
		#移除信件檔案
2069
		#函式說明:
2070
		#運用nohup與&來達到雖依序執行但不等待前一個指令執行完再執行下一個指令,形成假多工的執行每個指令.
2071
		#回傳結果: 
2072
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2073
		#$result["error"],錯誤訊息陣列.
2074
		#$result["function"],當前執行的函數名稱.
2075
		#$result["cmd"],執行的指令內容.
2076
		#$result["output"],爲執行完二元碼後的輸出陣列.
2077
		#必填參數:
2078
		#$conf["command"],字串陣列,要執行的指令與.
2079
		$conf["external::multiThreadsShell"]["command"]=$delMailFileCmd;
2080
		#$conf["fileArgu"],字串,變數__FILE__的內容.
2081
		$conf["external::multiThreadsShell"]["fileArgu"]=$conf["fileArgu"];		
2082
		#可省略參數:
2083
		#$conf["argu"],二維陣列字串,每個指令搭配的參數,預設為空陣列.
2084
		#$conf["argu"]=array(array());
2085
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
2086
		#$conf["enablePrintDescription"]="true";
2087
		#$conf["printDescription"],字串陣列,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
2088
		#$conf["printDescription"]=array("");
2089
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
2090
		#$conf["escapeshellarg"]="false";
2091
		#$conf["username"],字串陣列,每個指令要用什麼使用者來執行,預設為執行php使用者,該參數不適用於apache環境.
2092
		#$conf["username"]=array("");
2093
		#$conf["password"],字串陣列,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
2094
		#$conf["password"]=array("");
2095
		$multiThreadsShell=external::multiThreadsShell($conf["external::multiThreadsShell"]);
2096
		unset($conf["external::multiThreadsShell"]);
2097
 
2098
		#如果移除信件檔案失敗
2099
		if($multiThreadsShell["status"]=="false"){
2100
 
2101
			#設置錯誤識別
2102
			$result["status"]="false";
2103
 
2104
			#設置錯誤資訊
2105
			$result["error"]=$multiThreadsShell;
2106
 
2107
			#回傳結果
2108
			return $result;
2109
 
2110
			}
2111
 
2112
		*/			
2113
 
2114
		#設置執行正常
2115
		$result["status"]="true";
2116
 
2117
		#回傳結果
2118
		return $result;
2119
 
2120
		}#function multiCurlSmtp end
2121
 
2122
	/*
2123
	#函式說明:
2124
	#透過php的mail函數寄信
2125
	#回傳結果:
2126
	#$result["status"],寄信的情況,若爲"true",則十之八九沒有問題.
2127
	#$result["error"],錯誤訊息陣列
2128
	#$result["function"],當前執行的函數
2129
	#必填參數:
2130
	#$conf["to"],字串陣列,收件人們的信箱.
2131
	$conf["to"]=array();
2132
	#$conf["subject"],字串,郵件標題.
2133
	$conf["subject"]="";
2134
	#$conf["content"],字串,要寄送的訊息內容.
2135
	$conf["content"]="";
2136
	#可省略參數: 
2137
	#$conf["mailerEmail"],字串,顯示的寄件人.
2138
	#$conf["mailerEmail"]="";
2139
	#參考資料:
2140
	#mail=>https://www.php.net/manual/en/function.mail.php
2141
	#Internet Message Format=>http://www.faqs.org/rfcs/rfc2822
2142
	#備註:
2143
	#無.
2144
	*/
2145
	public static function sendMail(&$conf){
2146
 
2147
		#初始化要回傳的結果
2148
		$result=array();
2149
 
2150
		#儲存當前執行的函數
2151
		$result["function"]=__FUNCTION__;
2152
 
2153
		#如果 $conf 不為陣列
2154
		if(gettype($conf)!="array"){
2155
 
2156
			#設置執行失敗
2157
			$result["status"]="false";
2158
 
2159
			#設置執行錯誤訊息
2160
			$result["error"][]="\$conf變數須為陣列形態";
2161
 
2162
			#如果傳入的參數為 null
2163
			if($conf==null){
2164
 
2165
				#設置執行錯誤訊息
2166
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
2167
 
2168
				}#if end
2169
 
2170
			#回傳結果
2171
			return $result;
2172
 
2173
			}#if end
2174
 
2175
		#檢查參數
2176
		#函式說明:
2177
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
2178
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2179
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
2180
		#$result["function"],當前執行的函式名稱.
2181
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
2182
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
2183
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
2184
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
2185
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
2186
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
2187
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
2188
		#必填寫的參數:
2189
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
2190
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
2191
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
2192
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("to","subject","content");
2193
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); 
2194
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array","string","string");
2195
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
2196
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
2197
		#可以省略的參數:
2198
		#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
2199
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
2200
		#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
2201
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("mailerEmail");
2202
		#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double"); 
2203
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
2204
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
2205
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null);
2206
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
2207
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("subject","plainBody","htmlBody","receiverMail","receiverMailDisplay","receiverNameDisplay");
2208
		#參考資料來源:
2209
		#array_keys=>http://php.net/manual/en/function.array-keys.php
2210
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
2211
		unset($conf["variableCheck::checkArguments"]);
2212
 
2213
		#如果檢查失敗
2214
		if($checkArguments["status"]=="false"){
2215
 
2216
			#設置錯誤識別
2217
			$result["status"]="false";
2218
 
2219
			#設置錯誤訊息
2220
			$result["error"]=$checkArguments;
2221
 
2222
			#回傳結果
2223
			return $result;
2224
 
2225
			}#if end
2226
 
2227
		#如果檢查不通過
2228
		if($checkArguments["passed"]=="false"){
2229
 
2230
			#設置錯誤識別
2231
			$result["status"]="false";
2232
 
2233
			#設置錯誤訊息
2234
			$result["error"]=$checkArguments;
2235
 
2236
			#回傳結果
2237
			return $result;
2238
 
2239
			}#if end
2240
 
2241
		#函式說明:
2242
		#將一維陣列轉換為用特定符號間隔的字串,ex:array("1","2","3") to "a;b;c;".
2243
		#回傳的結果:
2244
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2245
		#$result["function"],當前執行的function名稱
2246
		#$result["error"],錯誤訊息陣列.
2247
		#$result["content"],處理好的字串.
2248
		#$result["argu"],使用的參數.
2249
		#必填參數:
2250
		#$conf["inputArray"],字串陣列,要轉成字串的一維陣列.
2251
		$conf["arrays::arrayToString"]["inputArray"]=$conf["to"];
2252
		#可省略參數:
2253
		#$conf["spiltSymbol"],字串,用來區隔字串的符號,預設為;
2254
		$conf["arrays::arrayToString"]["spiltSymbol"]=", ";
2255
		#$conf["skipEnd"],字串,結尾是否不要加上符號,預設為"false",要加上符號,"true"代表不要加上符號。
2256
		$conf["arrays::arrayToString"]["skipEnd"]="true";
2257
		#參考資料:
2258
		#無.
2259
		#備註:
2260
		#無.
2261
		$arrayToString=arrays::arrayToString($conf["arrays::arrayToString"]);
2262
		unset($conf["arrays::arrayToString"]);
2263
 
2264
		#如果檢查失敗
2265
		if($arrayToString["status"]=="false"){
2266
 
2267
			#設置錯誤識別
2268
			$result["status"]="false";
2269
 
2270
			#設置錯誤訊息
2271
			$result["error"]=$arrayToString;
2272
 
2273
			#回傳結果
2274
			return $result;
2275
 
2276
			}#if end
2277
 
2278
		$to = $arrayToString["content"];
2279
		$subject = $conf["subject"];
2280
		$message = $conf["content"];
2281
 
2282
		# In case any of our lines are larger than 70 characters, we should use wordwrap()
2283
		$message = wordwrap($message, 70, "\r\n");
2284
 
2285
		#初始化mail header為空
2286
		$headers = "";
2287
 
2288
		#如果有設置寄件人資訊
2289
		if(isset($conf["mailerEmail"])){
2290
 
2291
			#設置寄件人資訊
2292
			$headers = "From: ".$conf["mailerEmail"];
2293
 
2294
			}#if end
2295
 
2296
		#寄信
2297
		$mailResult=mail($to, $subject, $message, $headers);
2298
 
2299
		#初始化執行正常
2300
		$result["status"]="true";	
2301
 
2302
		#如果寄信失敗
2303
		if(!$mailResult){
2304
 
2305
			#設置執行不正常
2306
			$result["status"]="false";
2307
 
2308
			#回傳結果
2309
			return $result;
2310
 
2311
			}#if end
2312
 
2313
		#回傳結果
2314
		return $result;	
2315
 
2316
		}#function sendMail end
2317
 
2318
	}#class mail end
2319
 
2320
?>