| 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 |
#備註:
|
| 48 |
liveuser |
668 |
#Fedora42提供的curl指令不支援smtp協定,需要置換libcurl-minimal為libcurl.
|
| 3 |
liveuser |
669 |
*/
|
|
|
670 |
public static function curlSmtp(&$conf){
|
|
|
671 |
|
|
|
672 |
#初始化要回傳的結果
|
|
|
673 |
$result=array();
|
|
|
674 |
|
|
|
675 |
#儲存當前執行的函數
|
|
|
676 |
$result["function"]=__FUNCTION__;
|
|
|
677 |
|
|
|
678 |
#如果 $conf 不為陣列
|
|
|
679 |
if(gettype($conf)!="array"){
|
|
|
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 |
|
| 48 |
liveuser |
831 |
#取得 $systemTime
|
| 3 |
liveuser |
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."\"";
|
| 48 |
liveuser |
2016 |
|
| 3 |
liveuser |
2017 |
#清空 $mailFileHeader
|
|
|
2018 |
$mailFileHeader="";
|
|
|
2019 |
|
| 48 |
liveuser |
2020 |
}#for end
|
|
|
2021 |
|
| 3 |
liveuser |
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 |
#如果寄信失敗
|
| 48 |
liveuser |
2053 |
if($multiThreadsShell["status"]=="false"){
|
|
|
2054 |
|
| 3 |
liveuser |
2055 |
#設置錯誤識別
|
|
|
2056 |
$result["status"]="false";
|
|
|
2057 |
|
|
|
2058 |
#設置錯誤資訊
|
|
|
2059 |
$result["error"]=$multiThreadsShell;
|
|
|
2060 |
|
|
|
2061 |
#回傳結果
|
|
|
2062 |
return $result;
|
|
|
2063 |
|
| 48 |
liveuser |
2064 |
}#if end
|
|
|
2065 |
|
| 3 |
liveuser |
2066 |
#取得執行的指令
|
|
|
2067 |
$result["cmd"]=$multiThreadsShell["cmd"];
|
|
|
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 |
|
| 48 |
liveuser |
2114 |
*/
|
| 3 |
liveuser |
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 |
|
| 48 |
liveuser |
2320 |
/*
|
|
|
2321 |
#函式說明:
|
|
|
2322 |
#使用 php-pear-smtp 來透過SMTP伺服器寄信.
|
|
|
2323 |
#回傳結果:
|
|
|
2324 |
#$result["status"],執行正常與否,"true"代表正常;反之為"false".
|
|
|
2325 |
#$result["error"],錯誤訊息陣列
|
|
|
2326 |
#$result["function"],當前執行的函數.
|
|
|
2327 |
#必填參數:
|
|
|
2328 |
$conf["mailServer"],字串,要使用的SMTP郵件伺服器網址.若為tls加密,開頭請輸入"ssl://".
|
|
|
2329 |
$conf["mailServer"]="";
|
|
|
2330 |
#$conf["username"],字串,用來登入郵件伺服器的帳號
|
|
|
2331 |
$conf["username"]="";
|
|
|
2332 |
#$conf["password"],字串,用來登入郵件伺服器的密碼
|
|
|
2333 |
$conf["password"]="";
|
|
|
2334 |
#$conf["receiverMail"],陣列,收件人的信箱
|
|
|
2335 |
$conf["receiverMail"]=array("");
|
|
|
2336 |
#$conf["subject"],字串,郵件的主題
|
|
|
2337 |
$conf["subject"]="";
|
|
|
2338 |
#$conf["plainBody"],字串,郵件本文的純文字內容.
|
|
|
2339 |
$conf["plainBody"]="";
|
|
|
2340 |
#$conf["htmlBody"]="";,字串,郵件本文的html內容,多媒體盡量不要用base64的方式來嵌入,因為大部分的郵件服務(Gmail)都不支援,如果是在單機上的郵件軟體就可能有支援,例如:Evolution.
|
|
|
2341 |
$conf["htmlBody"]="";
|
|
|
2342 |
#可省略參數:
|
|
|
2343 |
#$conf["mailServerPort"],整數,smtp server的port,預設為465.
|
|
|
2344 |
#$conf["mailServerPort"]=465;
|
|
|
2345 |
#$conf["mailerMailDisplay"],字串,要顯示的寄件人信箱,預設爲 $conf["username"]
|
|
|
2346 |
#$conf["mailerMailDisplay"]="";
|
|
|
2347 |
#$conf["mailerNameDisplay"],字串,要顯示的寄件人姓名,預設爲 $conf["username"]
|
|
|
2348 |
#$conf["mailerNameDisplay"]="";
|
|
|
2349 |
#$conf["receiverMailDisplay"],陣列,要顯示的收件人信箱,預設爲 $conf["receiverMail"] 對應的元素.
|
|
|
2350 |
#$conf["receiverMailDisplay"]="";#
|
|
|
2351 |
#$conf["receiverNameDisplay"],陣列,要顯示的收件人姓名,預設爲 $conf["receiverMail"] 對應的元素.
|
|
|
2352 |
#$conf["receiverNameDisplay"]="";
|
|
|
2353 |
#$conf["attachment"],陣列,每個要寄送的附件路徑與檔案名稱
|
|
|
2354 |
#$conf["attachment"]=array();
|
|
|
2355 |
#$conf["attachmentName"],陣列,每個要寄送的附件顯示名稱,預設為$conf["attachment"]中的實際檔案名稱.
|
|
|
2356 |
#$conf["attachmentName"]=array();
|
|
|
2357 |
#$conf["attachmentMimeType"],陣列,每個附件的 mimeType,預設為"application/*".
|
|
|
2358 |
#$conf["attachmentMimeType"]array();
|
|
|
2359 |
#$conf["userAgent"],字串,用於表示使用smtp服務的軟體資訊,預設為"Powerd by QBPWCF(https://lib.qbpwcf.org)".
|
|
|
2360 |
#$conf["userAgent"]="Powerd by QBPWCF(https://lib.qbpwcf.org)";
|
|
|
2361 |
#$conf["org"],字串,若要表示來源組織名稱,可在此設定.
|
|
|
2362 |
#$conf["org"]="";
|
|
|
2363 |
#$conf["notifyReceived"],字串,回報已讀通知,預設為"true"代表要;反之為"false".
|
|
|
2364 |
#$conf["notifyReceived"]="true";
|
|
|
2365 |
#$conf["signWithGPGid"],字串,用於簽署的gpg id,預設不使用.
|
|
|
2366 |
#$conf["signWithGPGid"]="";
|
|
|
2367 |
#參考資料:
|
|
|
2368 |
#官網=>http://pear.php.net/package/Net_SMTP
|
|
|
2369 |
#Document=>https://github.com/pear/Net_SMTP
|
|
|
2370 |
#SSL=>https://github.com/pear/Net_SMTP?tab=readme-ov-file#secure-connections
|
|
|
2371 |
#Message-ID: =>https://datatracker.ietf.org/doc/html/rfc5322
|
|
|
2372 |
#mail body boundary=>https://www.w3.org/Protocols/rfc1341/7_2_Multipart.html
|
|
|
2373 |
#備註:
|
|
|
2374 |
#需要php-pear-Net-SMTP
|
|
|
2375 |
*/
|
|
|
2376 |
public static function pear_smtp_send(&$conf){
|
|
|
2377 |
|
|
|
2378 |
#初始化要回傳的結果
|
|
|
2379 |
$result=array();
|
|
|
2380 |
|
|
|
2381 |
#取得當前執行的函數名稱
|
|
|
2382 |
$result["function"]=__FUNCTION__;
|
|
|
2383 |
|
|
|
2384 |
#如果沒有參數
|
|
|
2385 |
if(func_num_args()==0){
|
|
|
2386 |
|
|
|
2387 |
#設置執行失敗
|
|
|
2388 |
$result["status"]="false";
|
|
|
2389 |
|
|
|
2390 |
#設置執行錯誤訊息
|
|
|
2391 |
$result["error"]="函數".$result["function"]."需要參數";
|
|
|
2392 |
|
|
|
2393 |
#回傳結果
|
|
|
2394 |
return $result;
|
|
|
2395 |
|
|
|
2396 |
}#if end
|
|
|
2397 |
|
|
|
2398 |
#取得參數
|
|
|
2399 |
$result["argu"]=$conf;
|
|
|
2400 |
|
|
|
2401 |
#如果 $conf 不為陣列
|
|
|
2402 |
if(gettype($conf)!=="array"){
|
|
|
2403 |
|
|
|
2404 |
#設置執行失敗
|
|
|
2405 |
$result["status"]="false";
|
|
|
2406 |
|
|
|
2407 |
#設置執行錯誤訊息
|
|
|
2408 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
2409 |
|
|
|
2410 |
#如果傳入的參數為 null
|
|
|
2411 |
if(is_null($conf)){
|
|
|
2412 |
|
|
|
2413 |
#設置執行錯誤訊息
|
|
|
2414 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
2415 |
|
|
|
2416 |
}#if end
|
|
|
2417 |
|
|
|
2418 |
#回傳結果
|
|
|
2419 |
return $result;
|
|
|
2420 |
|
|
|
2421 |
}#if end
|
|
|
2422 |
|
|
|
2423 |
#檢查參數
|
|
|
2424 |
#函式說明:
|
|
|
2425 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
|
|
|
2426 |
#回傳結果:
|
|
|
2427 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2428 |
#$result["error"],執行不正常結束的錯訊息陣列.
|
|
|
2429 |
#$result["simpleError"],簡單表示的錯誤訊息.
|
|
|
2430 |
#$result["function"],當前執行的函式名稱.
|
|
|
2431 |
#$result["argu"],設置給予的參數.
|
|
|
2432 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
2433 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
2434 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
2435 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
2436 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
2437 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
2438 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
2439 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
2440 |
#必填參數:
|
|
|
2441 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
2442 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
2443 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
2444 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
2445 |
#可省略參數:
|
|
|
2446 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
2447 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("username","password","receiverMail","subject","plainBody","htmlBody","mailServer");
|
|
|
2448 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null、any代表不指定變數形態.其中 resource也包含"resource (closed)".
|
|
|
2449 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","array","string","string","string","string");
|
|
|
2450 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
2451 |
#$conf["canBeEmptyString"]="false";
|
|
|
2452 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
2453 |
#$conf["canNotBeEmpty"]=array();
|
|
|
2454 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
2455 |
#$conf["canBeEmpty"]=array();
|
|
|
2456 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
2457 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
2458 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
2459 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("mailerMailDisplay","mailerNameDisplay","receiverNameDisplay","attachment","attachmentName","attachmentMimeType","mailServerPort","userAgent","org","notifyReceived","signWithGPGid");
|
|
|
2460 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
2461 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","array","array","array","array","integer","string","string","string","string");
|
|
|
2462 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
2463 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("\$conf[\"username\"]","\$conf[\"username\"]",array(),null,null,null,465,"Powerd by QBPWCF(https://lib.qbpwcf.org)",null,"true",null);
|
|
|
2464 |
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
|
|
|
2465 |
$conf["variableCheck::checkArguments"]["disallowAllSkipableVarIsEmpty"]="false";
|
|
|
2466 |
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
|
|
|
2467 |
$conf["variableCheck::checkArguments"]["disallowAllSkipableVarIsEmptyArray"]="false";
|
|
|
2468 |
#$conf["disallowAllSkipableVarNotExist"],字串,是否不允許每個可省略參數都不存在,預設為"false"代表允許,反之為"true".
|
|
|
2469 |
$conf["variableCheck::checkArguments"]["disallowAllSkipableVarNotExist"]="true";
|
|
|
2470 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
2471 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("receiverMailDisplay","receiverNameDisplay");
|
|
|
2472 |
#參考資料:
|
|
|
2473 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
2474 |
#備註:
|
|
|
2475 |
#無.
|
|
|
2476 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
2477 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
2478 |
|
|
|
2479 |
#如果檢查失敗
|
|
|
2480 |
if($checkArguments["status"]==="false"){
|
|
|
2481 |
|
|
|
2482 |
#設置錯誤識別
|
|
|
2483 |
$result["status"]="false";
|
|
|
2484 |
|
|
|
2485 |
#設置錯誤訊息
|
|
|
2486 |
$result["error"]=$checkArguments;
|
|
|
2487 |
|
|
|
2488 |
#回傳結果
|
|
|
2489 |
return $result;
|
|
|
2490 |
|
|
|
2491 |
}#if end
|
|
|
2492 |
|
|
|
2493 |
#如果檢查不通過
|
|
|
2494 |
if($checkArguments["passed"]==="false"){
|
|
|
2495 |
|
|
|
2496 |
#設置錯誤識別
|
|
|
2497 |
$result["status"]="false";
|
|
|
2498 |
|
|
|
2499 |
#設置錯誤訊息
|
|
|
2500 |
$result["error"]=$checkArguments;
|
|
|
2501 |
|
|
|
2502 |
#回傳結果
|
|
|
2503 |
return $result;
|
|
|
2504 |
|
|
|
2505 |
}#if end
|
|
|
2506 |
|
|
|
2507 |
#設置pear套件Net SMTP的位置
|
|
|
2508 |
$locationOfPearNetSmtp="/usr/share/pear/Net/SMTP.php";
|
|
|
2509 |
|
|
|
2510 |
#檢查需要的pear套件是否存在
|
|
|
2511 |
#函式說明:
|
|
|
2512 |
#檢查多個檔案與資料夾是否存在.
|
|
|
2513 |
#回傳的結果:
|
|
|
2514 |
#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
|
|
|
2515 |
#$result["error"],錯誤訊息陣列.
|
|
|
2516 |
#$resutl["function"],當前執行的涵式名稱.
|
|
|
2517 |
#$result["argu"],使用的參數.
|
|
|
2518 |
#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
|
|
|
2519 |
#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
|
|
|
2520 |
#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.
|
|
|
2521 |
#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址,若"web"參數為"true",才會有該內容.
|
|
|
2522 |
#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
|
|
|
2523 |
#必填參數:
|
|
|
2524 |
#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
|
|
|
2525 |
$conf["filAccess::checkMultiFileExist"]["fileArray"]=array($locationOfPearNetSmtp);
|
|
|
2526 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
2527 |
$conf["filAccess::checkMultiFileExist"]["fileArgu"]=__FILE__;
|
|
|
2528 |
#可省略參數:
|
|
|
2529 |
#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
|
|
|
2530 |
$conf["filAccess::checkMultiFileExist"]["disableWebSearch"]="true";
|
|
|
2531 |
#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
|
|
|
2532 |
$conf["filAccess::checkMultiFileExist"]["userDir"]="false";
|
|
|
2533 |
#$conf["web"],字串,檔案是放在web就是"true",反之為檔案系統"false",預設為"true".
|
|
|
2534 |
$conf["filAccess::checkMultiFileExist"]["web"]="false";
|
|
|
2535 |
#參考資料:
|
|
|
2536 |
#http://php.net/manual/en/function.file-exists.php
|
|
|
2537 |
#http://php.net/manual/en/control-structures.foreach.php
|
|
|
2538 |
#備註:
|
|
|
2539 |
#函數file_exists檢查的路徑為檔案系統的路徑
|
|
|
2540 |
#$result["varName"][$i]結果未實作
|
|
|
2541 |
$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["filAccess::checkMultiFileExist"]);
|
|
|
2542 |
unset($conf["filAccess::checkMultiFileExist"]);
|
|
|
2543 |
|
|
|
2544 |
#如果檢查失敗
|
|
|
2545 |
if($checkMultiFileExist["status"]==="false"){
|
|
|
2546 |
|
|
|
2547 |
#設置錯誤識別
|
|
|
2548 |
$result["status"]="false";
|
|
|
2549 |
|
|
|
2550 |
#設置錯誤訊息
|
|
|
2551 |
$result["error"]=$checkMultiFileExist;
|
|
|
2552 |
|
|
|
2553 |
#回傳結果
|
|
|
2554 |
return $result;
|
|
|
2555 |
|
|
|
2556 |
}#if end
|
|
|
2557 |
|
|
|
2558 |
#如果套件不存在
|
|
|
2559 |
if($checkMultiFileExist["allExist"]==="false"){
|
|
|
2560 |
|
|
|
2561 |
#設置錯誤識別
|
|
|
2562 |
$result["status"]="false";
|
|
|
2563 |
|
|
|
2564 |
#設置錯誤訊息
|
|
|
2565 |
$result["error"][]=$checkMultiFileExist;
|
|
|
2566 |
|
|
|
2567 |
#設置錯誤訊息
|
|
|
2568 |
$result["error"][]="請確認 ".$locationOfPearNetSmtp." 可被存取";
|
|
|
2569 |
|
|
|
2570 |
#回傳結果
|
|
|
2571 |
return $result;
|
|
|
2572 |
|
|
|
2573 |
}#if end
|
|
|
2574 |
|
|
|
2575 |
#匯入需要的pear套件
|
|
|
2576 |
require_once($locationOfPearNetSmtp);
|
|
|
2577 |
|
|
|
2578 |
#create smtp object
|
|
|
2579 |
$smtp = new \Net_SMTP($conf["mailServer"], $conf["mailServerPort"]);
|
|
|
2580 |
|
|
|
2581 |
#如果有錯誤
|
|
|
2582 |
if(\PEAR::isError($error = $smtp->connect())){
|
|
|
2583 |
|
|
|
2584 |
#設置錯誤識別
|
|
|
2585 |
$result["status"]="false";
|
|
|
2586 |
|
|
|
2587 |
#設置錯誤訊息
|
|
|
2588 |
$result["error"]=$error->getMessage();
|
|
|
2589 |
|
|
|
2590 |
#回傳結果
|
|
|
2591 |
return $result;
|
|
|
2592 |
|
|
|
2593 |
}#if end
|
|
|
2594 |
|
|
|
2595 |
#嘗試進行登入認證,方式目前都用"PLAIN"
|
|
|
2596 |
$smtp->auth($conf["username"],$conf["password"],"PLAIN");
|
|
|
2597 |
|
|
|
2598 |
# smtp command "MAIL FROM:"
|
|
|
2599 |
$smtp->mailFrom($conf["mailerNameDisplay"]." <".$conf["mailerMailDisplay"].">");
|
|
|
2600 |
|
|
|
2601 |
#初始化儲存 email head 的變數
|
|
|
2602 |
$head="";
|
|
|
2603 |
|
|
|
2604 |
#初始化儲存 email data 的變數
|
|
|
2605 |
$data="";
|
|
|
2606 |
|
|
|
2607 |
#設置收件人
|
|
|
2608 |
foreach($conf["receiverMail"] as $index => $receiverMail){
|
|
|
2609 |
|
|
|
2610 |
#若無顯示名稱參數
|
|
|
2611 |
if(!isset($conf["receiverNameDisplay"][$index])){
|
|
|
2612 |
|
|
|
2613 |
#若無顯示名稱參數,則預設採email來顯示.
|
|
|
2614 |
$conf["receiverNameDisplay"][$index]=$receiverMail;
|
|
|
2615 |
|
|
|
2616 |
}#if end
|
|
|
2617 |
|
|
|
2618 |
#設置收件人的email與顯示名稱
|
|
|
2619 |
$receiverMail=$conf["receiverNameDisplay"][$index]." <".$receiverMail.">";
|
|
|
2620 |
|
|
|
2621 |
#設置To:資訊
|
|
|
2622 |
$head=$head."To: ".$receiverMail."\r\n";
|
|
|
2623 |
|
|
|
2624 |
#如果新增收件人失敗
|
|
|
2625 |
if(\PEAR::isError($res=$smtp->rcptTo($receiverMail))){
|
|
|
2626 |
|
|
|
2627 |
#設置錯誤識別
|
|
|
2628 |
$result["status"]="false";
|
|
|
2629 |
|
|
|
2630 |
#設置錯誤訊息
|
|
|
2631 |
$result["error"]="Unable to add recipient <".$receiverMail.">: ".$res->getMessage();
|
|
|
2632 |
|
|
|
2633 |
#回傳結果
|
|
|
2634 |
return $result;
|
|
|
2635 |
|
|
|
2636 |
}#if end
|
|
|
2637 |
|
|
|
2638 |
}#foreach end
|
|
|
2639 |
|
|
|
2640 |
#設置sender資訊
|
|
|
2641 |
$head=$head."From: ".$conf["mailerNameDisplay"]." <".$conf["mailerMailDisplay"].">"."\r\n";
|
|
|
2642 |
|
|
|
2643 |
#設置Replay-to資訊
|
|
|
2644 |
$head=$head."Reply-To: ".$conf["mailerNameDisplay"]." <".$conf["mailerMailDisplay"].">"."\r\n";
|
|
|
2645 |
|
|
|
2646 |
#如果有設置回報已讀通知
|
|
|
2647 |
if($conf["notifyReceived"]==="true"){
|
|
|
2648 |
|
|
|
2649 |
#Disposition-Notification-To: liveuser@qbpwcf.org
|
|
|
2650 |
$head=$head."Disposition-Notification-To: ".$conf["mailerMailDisplay"]."\r\n";
|
|
|
2651 |
|
|
|
2652 |
}#if end
|
|
|
2653 |
|
|
|
2654 |
#建立body中的Subject
|
|
|
2655 |
$head=$head."Subject: ".$conf["subject"]."\r\n";
|
|
|
2656 |
|
|
|
2657 |
#函式說明:
|
|
|
2658 |
#使用 linux 的 uuid 指令來產生 uuid 字串
|
|
|
2659 |
#回傳結果:
|
|
|
2660 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2661 |
#$result["error"],錯誤訊息.
|
|
|
2662 |
#$result["function"],當前執行的函式名稱.
|
|
|
2663 |
#$result["content"],uuid.
|
|
|
2664 |
#必填參數:
|
|
|
2665 |
#無.
|
|
|
2666 |
#可省略參數:
|
|
|
2667 |
#無.
|
|
|
2668 |
#參考資料:
|
|
|
2669 |
#無.
|
|
|
2670 |
#備註:
|
|
|
2671 |
#無.
|
|
|
2672 |
$uuid=cmd::uuid();
|
|
|
2673 |
|
|
|
2674 |
#如果取得uuid失敗
|
|
|
2675 |
if($uuid["status"]==="false"){
|
|
|
2676 |
|
|
|
2677 |
#設置錯誤識別
|
|
|
2678 |
$result["status"]="false";
|
|
|
2679 |
|
|
|
2680 |
#設置錯誤訊息
|
|
|
2681 |
$result["error"][]="Unable to create Message-ID";
|
|
|
2682 |
|
|
|
2683 |
#設置錯誤訊息
|
|
|
2684 |
$result["error"][]=$uuid;
|
|
|
2685 |
|
|
|
2686 |
#回傳結果
|
|
|
2687 |
return $result;
|
|
|
2688 |
|
|
|
2689 |
}#if end
|
|
|
2690 |
|
|
|
2691 |
#函式說明:
|
|
|
2692 |
#將字串特定關鍵字與其前面的內容剔除
|
|
|
2693 |
#回傳結果:
|
|
|
2694 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2695 |
#$result["error"],錯誤訊息陣列.
|
|
|
2696 |
#$result["warning"],警告訊息鎮列.
|
|
|
2697 |
#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
|
|
|
2698 |
#$result["function"],當前執行的函數名稱.
|
|
|
2699 |
#$result["argu"],使用的參數.
|
|
|
2700 |
#$result["oriStr"],要處理的原始字串內容.
|
|
|
2701 |
#$result["content"],處理好的的字串內容.
|
|
|
2702 |
#$result["deleted"],被移除的內容.
|
|
|
2703 |
#必填參數:
|
|
|
2704 |
#$conf["stringIn"],字串,要處理的字串.
|
|
|
2705 |
$conf["stringProcess::delStrBeforeKeyWord"]["stringIn"]=$conf["mailServer"];
|
|
|
2706 |
#$conf["keyWord"],字串,特定字串.
|
|
|
2707 |
$conf["stringProcess::delStrBeforeKeyWord"]["keyWord"]="//";
|
|
|
2708 |
#可省略參數:
|
|
|
2709 |
#$conf["recursive"],字串,預設為"false"代表找到一個關鍵字就會停止;"true"代表會即重複執行,知道沒有關鍵字為止.
|
|
|
2710 |
$conf["stringProcess::delStrBeforeKeyWord"]["recursive"]="true";
|
|
|
2711 |
#$conf["lastResult"],陣列,本函式前次執行的結果,若沒有找到關鍵字,則會改回傳該內容.
|
|
|
2712 |
#$conf["lastResult"]=$delStrBeforeKeyWord;
|
|
|
2713 |
#參考資料:
|
|
|
2714 |
#無.
|
|
|
2715 |
#備註:
|
|
|
2716 |
#無.
|
|
|
2717 |
$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf["stringProcess::delStrBeforeKeyWord"]);
|
|
|
2718 |
unset($conf["stringProcess::delStrBeforeKeyWord"]);
|
|
|
2719 |
|
|
|
2720 |
#如果取得Message-ID的domain失敗
|
|
|
2721 |
if($delStrBeforeKeyWord["status"]==="false"){
|
|
|
2722 |
|
|
|
2723 |
#設置錯誤識別
|
|
|
2724 |
$result["status"]="false";
|
|
|
2725 |
|
|
|
2726 |
#設置錯誤訊息
|
|
|
2727 |
$result["error"][]="Unable to create domain of Message-ID";
|
|
|
2728 |
|
|
|
2729 |
#設置錯誤訊息
|
|
|
2730 |
$result["error"][]=$delStrBeforeKeyWord;
|
|
|
2731 |
|
|
|
2732 |
#回傳結果
|
|
|
2733 |
return $result;
|
|
|
2734 |
|
|
|
2735 |
}#if end
|
|
|
2736 |
|
|
|
2737 |
#取得Message-ID對應的domain
|
|
|
2738 |
$MessageIdDomain=$delStrBeforeKeyWord["content"];
|
|
|
2739 |
|
|
|
2740 |
#建立Message-ID
|
|
|
2741 |
$head=$head."Message-ID: <".$uuid["content"]."@".$MessageIdDomain.">"."\r\n";;
|
|
|
2742 |
|
|
|
2743 |
#設置User-Agent
|
|
|
2744 |
$head=$head."User-Agent: ".$conf["userAgent"]."\r\n";
|
|
|
2745 |
|
|
|
2746 |
#設置Date:
|
|
|
2747 |
$head=$head."Date: ".gmdate("Y-m-d H:i:s")."\r\n";
|
|
|
2748 |
|
|
|
2749 |
#如果有設置 org
|
|
|
2750 |
if(isset($conf["org"])){
|
|
|
2751 |
|
|
|
2752 |
#設置 Organization
|
|
|
2753 |
$head=$head."Organization: ".$conf["org"]."\r\n";
|
|
|
2754 |
|
|
|
2755 |
}#if end
|
|
|
2756 |
|
|
|
2757 |
#函式說明:
|
|
|
2758 |
#建立以圖片(PNG格式)呈現的驗證碼.
|
|
|
2759 |
#回傳的解果:
|
|
|
2760 |
#$result["status"],執行是否正常,"true"代表執行成功,"false"代表執行失敗.
|
|
|
2761 |
#$result["error"],錯誤訊息.
|
|
|
2762 |
#$result["function"],檔前執行的函數名稱.
|
|
|
2763 |
#$result["randNumberWord"],傳驗證碼的內容.
|
|
|
2764 |
#$result["imgAddress"],包含src圖片的位置與名稱.
|
|
|
2765 |
#$result["imgSrcVal"],放在src裏面的圖片位置與名稱.
|
|
|
2766 |
#必填參數:
|
|
|
2767 |
#$conf["imgAddressAndName"],字串,爲驗證碼圖片儲存的位置與名稱,副檔名程式會自動產生
|
|
|
2768 |
$conf["authenticate::validationCode"]["imgAddressAndName"]="/tmp/xxx.png";
|
|
|
2769 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
2770 |
$conf["authenticate::validationCode"]["fileArgu"]=__FILE__;
|
|
|
2771 |
#可省略參數:
|
|
|
2772 |
#$conf["num"],字串,爲驗證碼的位數,請輸入阿拉伯數字,預設為"8"位數.
|
|
|
2773 |
#$conf["num"]="8";
|
|
|
2774 |
#$conf["disableImg"],字串,是否要取消驗證碼圖片的輸出,"true"為要取消,預設為"false"為不取消
|
|
|
2775 |
$conf["authenticate::validationCode"]["disableImg"]="true";
|
|
|
2776 |
#$conf["imgToData"],字串,預設為"true"代表將圖片轉存成base64圖片,並將原始圖片移除;反之為"false"
|
|
|
2777 |
#$conf["imgToData"]="true";
|
|
|
2778 |
#$conf["class"],字串,圖片要套用的css樣式類別.
|
|
|
2779 |
#$conf["class"]="";
|
|
|
2780 |
#$conf["content"],字串陣列,允許的亂數陣列內容,預設爲(1~9 and A~Z).
|
|
|
2781 |
#$conf["content"]=array();
|
|
|
2782 |
#參考資料:
|
|
|
2783 |
#無.
|
|
|
2784 |
#備註:
|
|
|
2785 |
#無.
|
|
|
2786 |
$validationCode=authenticate::validationCode($conf["authenticate::validationCode"]);
|
|
|
2787 |
unset($conf["authenticate::validationCode"]);
|
|
|
2788 |
|
|
|
2789 |
#如果檢查失敗
|
|
|
2790 |
if($validationCode["status"]==="false"){
|
|
|
2791 |
|
|
|
2792 |
#設置錯誤識別
|
|
|
2793 |
$result["status"]="false";
|
|
|
2794 |
|
|
|
2795 |
#設置錯誤訊息
|
|
|
2796 |
$result["error"]=$validationCode;
|
|
|
2797 |
|
|
|
2798 |
#回傳結果
|
|
|
2799 |
return $result;
|
|
|
2800 |
|
|
|
2801 |
}#if end
|
|
|
2802 |
|
|
|
2803 |
#初始化 boundary
|
|
|
2804 |
$boundary=$validationCode["randNumberWord"];
|
|
|
2805 |
|
|
|
2806 |
#初始化 boundary start
|
|
|
2807 |
$boundaryS="--".$boundary;
|
|
|
2808 |
|
|
|
2809 |
#初始化 boundary end
|
|
|
2810 |
$boundaryE=$boundaryS."--";
|
|
|
2811 |
|
|
|
2812 |
#取得放置於head的Contet-Type描述
|
|
|
2813 |
$contentDescInHead="Content-Type: multipart/alternative; boundary=\"".$boundary."\"\r\n";
|
|
|
2814 |
|
|
|
2815 |
#設置信件本文(純文字與html兩種)
|
|
|
2816 |
$data=$data.$boundaryS."\r\n";
|
|
|
2817 |
$data=$data."Content-Type: text/plain; charset=UTF-8\r\n";
|
|
|
2818 |
$data=$data."\r\n";
|
|
|
2819 |
$data=$data.$conf["plainBody"]."\r\n";
|
|
|
2820 |
$data=$data."\r\n";
|
|
|
2821 |
$data=$data.$boundaryS."\r\n";
|
|
|
2822 |
$data=$data."Content-Type: text/html; charset=UTF-8\r\n";
|
|
|
2823 |
$data=$data."\r\n";
|
|
|
2824 |
$data=$data.$conf["htmlBody"]."\r\n";
|
|
|
2825 |
$data=$data.$boundaryE."\r\n";
|
|
|
2826 |
|
|
|
2827 |
#如果有設定要上傳附件
|
|
|
2828 |
if(isset($conf["attachment"])){
|
|
|
2829 |
|
|
|
2830 |
#依據每個附件
|
|
|
2831 |
for($i=0;$i<count($conf["attachment"]);$i++){
|
|
|
2832 |
|
|
|
2833 |
#初始化寄送附件的語法
|
|
|
2834 |
$attachment="";
|
|
|
2835 |
|
|
|
2836 |
#確認目標檔案是否存在
|
|
|
2837 |
#函式說明:檢查多個檔案是否存在
|
|
|
2838 |
#回傳的結果:
|
|
|
2839 |
#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
|
|
|
2840 |
#$result["error"],錯誤訊息陣列.
|
|
|
2841 |
#$resutl["function"],當前執行的涵式名稱.
|
|
|
2842 |
#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
|
|
|
2843 |
#$result["varName"][$i],爲第$i個資料夾或檔案的名稱。
|
|
|
2844 |
#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
|
|
|
2845 |
#必填參數:
|
|
|
2846 |
$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
|
|
|
2847 |
$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($conf["attachment"][$i]);#要檢查書否存在的檔案有哪些,須爲一維陣列數值。
|
|
|
2848 |
#參考資料來源:
|
|
|
2849 |
#http://php.net/manual/en/function.file-exists.php
|
|
|
2850 |
#http://php.net/manual/en/control-structures.foreach.php
|
|
|
2851 |
$checkMutiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
|
|
|
2852 |
unset($conf["fileAccess::checkMultiFileExist"]);
|
|
|
2853 |
|
|
|
2854 |
#如果檢查失敗
|
|
|
2855 |
if($checkMutiFileExist["status"]=="false"){
|
|
|
2856 |
|
|
|
2857 |
#設置錯誤識別
|
|
|
2858 |
$result["status"]="false";
|
|
|
2859 |
|
|
|
2860 |
#設置錯誤資訊
|
|
|
2861 |
$result["error"]=$checkMutiFileExist;
|
|
|
2862 |
|
|
|
2863 |
#回傳結果
|
|
|
2864 |
return $result;
|
|
|
2865 |
|
|
|
2866 |
}#if end
|
|
|
2867 |
|
|
|
2868 |
#如果檔案不存在
|
|
|
2869 |
if($checkMutiFileExist["varExist"][0]=="false"){
|
|
|
2870 |
|
|
|
2871 |
#設置錯誤識別
|
|
|
2872 |
$result["status"]="false";
|
|
|
2873 |
|
|
|
2874 |
#設置錯誤資訊
|
|
|
2875 |
$result["error"]=$checkMutiFileExist;
|
|
|
2876 |
|
|
|
2877 |
#回傳結果
|
|
|
2878 |
return $result;
|
|
|
2879 |
|
|
|
2880 |
}#if end
|
|
|
2881 |
|
|
|
2882 |
#如果是第一個附件
|
|
|
2883 |
if($i===0){
|
|
|
2884 |
|
|
|
2885 |
#在前面加上 multipart/mixed 的 boundary
|
|
|
2886 |
$data="Content-Type: multipart/mixed; boundary=".$boundary."\r\n\r\n".$data;
|
|
|
2887 |
|
|
|
2888 |
}#if end
|
|
|
2889 |
|
|
|
2890 |
#如果 $conf["attachmentName"] 不存在
|
|
|
2891 |
if(!isset($conf["attachmentName"])){
|
|
|
2892 |
|
|
|
2893 |
#涵是說明:
|
|
|
2894 |
#取得檔案路徑字串的路徑與檔案的名稱與檔案副檔名
|
|
|
2895 |
#回傳的結果:
|
|
|
2896 |
#$result["status"],執行是否正常,"true"正常,"false"代表不正常.
|
|
|
2897 |
#$result["error"],錯誤訊息.
|
|
|
2898 |
#$result["function"],當前執行的函式名稱.
|
|
|
2899 |
#$result["filePath"],路徑字串.
|
|
|
2900 |
#$result["fileName"],檔案名稱字串.
|
|
|
2901 |
#$result["fileExtention"],檔案的副檔名.
|
|
|
2902 |
#$result["fullFileName"],含副檔名的檔案名稱.
|
|
|
2903 |
#$result["fullFilePathAndName"],完整的檔案路徑(含副檔名).
|
|
|
2904 |
#必填參數:
|
|
|
2905 |
#$conf["fileAddressAndName"],字串,檔案名稱與其路徑.
|
|
|
2906 |
$conf["fileAccess::getFileAddressAndNameAndFileExtention"]["fileAddressAndName"]=$conf["attachment"][$i];
|
|
|
2907 |
#可省略的參數:
|
|
|
2908 |
#無.
|
|
|
2909 |
$getFileAddressAndNameAndFileExtention=fileAccess::getFileAddressAndNameAndFileExtention($conf["fileAccess::getFileAddressAndNameAndFileExtention"]);
|
|
|
2910 |
unset($conf["fileAccess::getFileAddressAndNameAndFileExtention"]);
|
|
|
2911 |
|
|
|
2912 |
#如果解析檔案資訊失敗
|
|
|
2913 |
if($getFileAddressAndNameAndFileExtention["status"]==="false"){
|
|
|
2914 |
|
|
|
2915 |
#設置錯誤識別
|
|
|
2916 |
$result["status"]="false";
|
|
|
2917 |
|
|
|
2918 |
#設置錯誤資訊
|
|
|
2919 |
$result["error"]=$getFileAddressAndNameAndFileExtention;
|
|
|
2920 |
|
|
|
2921 |
#回傳結果
|
|
|
2922 |
return $result;
|
|
|
2923 |
|
|
|
2924 |
}#if end
|
|
|
2925 |
|
|
|
2926 |
#設定附件名稱
|
|
|
2927 |
$conf["attachmentName"][$i]=$getFileAddressAndNameAndFileExtention["fullFileName"];
|
|
|
2928 |
|
|
|
2929 |
}#if end
|
|
|
2930 |
|
|
|
2931 |
#反之如果 $conf["attachmentName"][$i] 不存在
|
|
|
2932 |
else if(!isset($conf["attachmentName"][$i])){
|
|
|
2933 |
|
|
|
2934 |
#涵是說明:
|
|
|
2935 |
#取得檔案路徑字串的路徑與檔案的名稱與檔案副檔名
|
|
|
2936 |
#回傳的結果:
|
|
|
2937 |
#$result["status"],執行是否正常,"true"正常,"false"代表不正常.
|
|
|
2938 |
#$result["error"],錯誤訊息.
|
|
|
2939 |
#$result["function"],當前執行的函式名稱.
|
|
|
2940 |
#$result["filePath"],路徑字串.
|
|
|
2941 |
#$result["fileName"],檔案名稱字串.
|
|
|
2942 |
#$result["fileExtention"],檔案的副檔名.
|
|
|
2943 |
#$result["fullFileName"],含副檔名的檔案名稱.
|
|
|
2944 |
#$result["fullFilePathAndName"],完整的檔案路徑(含副檔名).
|
|
|
2945 |
#必填參數:
|
|
|
2946 |
#$conf["fileAddressAndName"],字串,檔案名稱與其路徑.
|
|
|
2947 |
$conf["fileAccess::getFileAddressAndNameAndFileExtention"]["fileAddressAndName"]=$conf["attachment"][$i];
|
|
|
2948 |
#可省略的參數:
|
|
|
2949 |
#無.
|
|
|
2950 |
$getFileAddressAndNameAndFileExtention=fileAccess::getFileAddressAndNameAndFileExtention($conf["fileAccess::getFileAddressAndNameAndFileExtention"]);
|
|
|
2951 |
unset($conf["fileAccess::getFileAddressAndNameAndFileExtention"]);
|
|
|
2952 |
|
|
|
2953 |
#如果解析檔案資訊失敗
|
|
|
2954 |
if($getFileAddressAndNameAndFileExtention["status"]=="false"){
|
|
|
2955 |
|
|
|
2956 |
#設置錯誤識別
|
|
|
2957 |
$result["status"]="false";
|
|
|
2958 |
|
|
|
2959 |
#設置錯誤資訊
|
|
|
2960 |
$result["error"]=$getFileAddressAndNameAndFileExtention;
|
|
|
2961 |
|
|
|
2962 |
#回傳結果
|
|
|
2963 |
return $result;
|
|
|
2964 |
|
|
|
2965 |
}#if end
|
|
|
2966 |
|
|
|
2967 |
#設定附件名稱
|
|
|
2968 |
$conf["attachmentName"][$i]=$getFileAddressAndNameAndFileExtention["fullFileName"];
|
|
|
2969 |
|
|
|
2970 |
}#if end
|
|
|
2971 |
|
|
|
2972 |
#如果 $conf["attachmentMimeType"] 不存在
|
|
|
2973 |
if(!isset($conf["attachmentMimeType"])){
|
|
|
2974 |
|
|
|
2975 |
#設定檔案類型
|
|
|
2976 |
$conf["attachmentMimeType"][$i]="application/*";
|
|
|
2977 |
|
|
|
2978 |
}#if end
|
|
|
2979 |
|
|
|
2980 |
#反之如果 $conf["attachmentMimeType"][$i] 不存在
|
|
|
2981 |
if(!isset($conf["attachmentMimeType"][$i])){
|
|
|
2982 |
|
|
|
2983 |
$conf["attachmentMimeType"][$i]="application/*";
|
|
|
2984 |
|
|
|
2985 |
}#if end
|
|
|
2986 |
|
|
|
2987 |
#加上寄送附件的語法
|
|
|
2988 |
$attachment=$attachment.$boundaryS."\r\n";
|
|
|
2989 |
$attachment=$attachment."Content-Type: ".$conf["attachmentMimeType"][$i]."; name=".$conf["attachmentName"][$i]."\r\n";
|
|
|
2990 |
$attachment=$attachment."Content-Disposition: attachment; filename=".$conf["attachmentName"][$i]."\r\n";
|
|
|
2991 |
$attachment=$attachment."Content-Transfer-Encoding: base64\r\n";
|
|
|
2992 |
$attachment=$attachment."X-Attachment-Id: f_io1ikfii".$i."\r\n";
|
|
|
2993 |
|
|
|
2994 |
#將檔案用base64加密
|
|
|
2995 |
$base64fileStr=base64_encode(file_get_contents($conf["attachment"][$i]));
|
|
|
2996 |
|
|
|
2997 |
#依據規定,每列不得大於70的字元
|
|
|
2998 |
#$wordwrapedFileStr=wordwrap($base64fileStr,70,"\r\n",true);
|
|
|
2999 |
|
|
|
3000 |
#斷行後附加檔案字串
|
|
|
3001 |
#$attachment=$attachment."\r\n".$wordwrapedFileStr."\r\n";
|
|
|
3002 |
|
|
|
3003 |
#斷行後附加檔案字串
|
|
|
3004 |
$attachment=$attachment."\r\n".$base64fileStr."\r\n";
|
|
|
3005 |
|
|
|
3006 |
#如果是最後一個附件
|
|
|
3007 |
if($i===count($conf["attachment"])-1){
|
|
|
3008 |
|
|
|
3009 |
#混合資料結尾
|
|
|
3010 |
$attachment=$attachment.$boundary."\r\n";
|
|
|
3011 |
|
|
|
3012 |
}#if end
|
|
|
3013 |
|
|
|
3014 |
#增加到信件內文的結尾
|
|
|
3015 |
$data=$data.$attachment;
|
|
|
3016 |
|
|
|
3017 |
}#for end
|
|
|
3018 |
|
|
|
3019 |
}#if end
|
|
|
3020 |
|
|
|
3021 |
#body end
|
|
|
3022 |
|
|
|
3023 |
#如果有指定 signWithGPGid
|
|
|
3024 |
if(isset($conf["signWithGPGid"])){
|
|
|
3025 |
|
|
|
3026 |
#將原本的 Content-Type 放到 data 前面.
|
|
|
3027 |
$data=$contentDescInHead.$data;
|
|
|
3028 |
|
|
|
3029 |
#用gpg指令簽署body
|
|
|
3030 |
#函式說明:
|
|
|
3031 |
#呼叫shell執行系統命令,並取得回傳的內容.
|
|
|
3032 |
#回傳結果:
|
|
|
3033 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
3034 |
#$result["error"],錯誤訊息陣列.
|
|
|
3035 |
#$result["function"],當前執行的函數名稱.
|
|
|
3036 |
#$result["argu"],使用的參數.
|
|
|
3037 |
#$result["cmd"],執行的指令內容.
|
|
|
3038 |
#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
|
|
|
3039 |
#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
|
|
|
3040 |
#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
|
|
|
3041 |
#$result["running"],是否還在執行.
|
|
|
3042 |
#$result["pid"],pid.
|
|
|
3043 |
#$result["statusCode"],執行結束後的代碼.
|
|
|
3044 |
#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
|
|
|
3045 |
#必填參數:
|
|
|
3046 |
#$conf["command"],字串,要執行的指令.
|
|
|
3047 |
$conf["external::callShell"]["command"]="echo";
|
|
|
3048 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
3049 |
$conf["external::callShell"]["fileArgu"]=__FILE__;
|
|
|
3050 |
#可省略參數:
|
|
|
3051 |
#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
|
|
|
3052 |
$conf["external::callShell"]["argu"]=array($data,"|","gpg","-u",$conf["signWithGPGid"],"-s","--clear-sign");
|
|
|
3053 |
#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
|
|
|
3054 |
#$conf["arguIsAddr"]=array();
|
|
|
3055 |
#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
|
|
|
3056 |
#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
|
|
|
3057 |
#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
|
|
|
3058 |
#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
|
|
|
3059 |
#$conf["enablePrintDescription"]="true";
|
|
|
3060 |
#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
|
|
|
3061 |
#$conf["printDescription"]="";
|
|
|
3062 |
#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
|
|
|
3063 |
$conf["external::callShell"]["escapeshellarg"]="true";
|
|
|
3064 |
#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
|
|
|
3065 |
#$conf["thereIsShellVar"]=array();
|
|
|
3066 |
#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
|
|
|
3067 |
#$conf["username"]="";
|
|
|
3068 |
#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
|
|
|
3069 |
#$conf["password"]="";
|
|
|
3070 |
#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
|
|
|
3071 |
#$conf["useScript"]="";
|
|
|
3072 |
#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
|
|
|
3073 |
#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
|
|
|
3074 |
#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
|
|
|
3075 |
#$conf["inBackGround"]="";
|
|
|
3076 |
#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
|
|
|
3077 |
#$conf["getErr"]="false";
|
|
|
3078 |
#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
|
|
|
3079 |
#$conf["doNotRun"]="false";
|
|
|
3080 |
#參考資料:
|
|
|
3081 |
#exec=>http://php.net/manual/en/function.exec.php
|
|
|
3082 |
#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
|
|
|
3083 |
#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
|
|
|
3084 |
#備註:
|
|
|
3085 |
#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
|
|
|
3086 |
#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
|
|
|
3087 |
$callShell=external::callShell($conf["external::callShell"]);
|
|
|
3088 |
unset($conf["external::callShell"]);
|
|
|
3089 |
|
|
|
3090 |
#如果解析檔案資訊失敗
|
|
|
3091 |
if($callShell["status"]==="false"){
|
|
|
3092 |
|
|
|
3093 |
#設置錯誤識別
|
|
|
3094 |
$result["status"]="false";
|
|
|
3095 |
|
|
|
3096 |
#設置錯誤資訊
|
|
|
3097 |
$result["error"]=$callShell;
|
|
|
3098 |
|
|
|
3099 |
#回傳結果
|
|
|
3100 |
return $result;
|
|
|
3101 |
|
|
|
3102 |
}#if end
|
|
|
3103 |
|
|
|
3104 |
#如果輸出的內容有異常
|
|
|
3105 |
if($callShell["output"][0]!=="-----BEGIN PGP SIGNED MESSAGE-----"){
|
|
|
3106 |
|
|
|
3107 |
#設置錯誤識別
|
|
|
3108 |
$result["status"]="false";
|
|
|
3109 |
|
|
|
3110 |
#設置錯誤資訊
|
|
|
3111 |
$result["error"]=$callShell;
|
|
|
3112 |
|
|
|
3113 |
#回傳結果
|
|
|
3114 |
return $result;
|
|
|
3115 |
|
|
|
3116 |
}#if end
|
|
|
3117 |
|
|
|
3118 |
#如果簽署所用的方式不是SHA512
|
|
|
3119 |
if($callShell["output"][1]!=="Hash: SHA512"){
|
|
|
3120 |
|
|
|
3121 |
#設置錯誤識別
|
|
|
3122 |
$result["status"]="false";
|
|
|
3123 |
|
|
|
3124 |
#設置錯誤資訊
|
|
|
3125 |
$result["error"]=$callShell;
|
|
|
3126 |
|
|
|
3127 |
#回傳結果
|
|
|
3128 |
return $result;
|
|
|
3129 |
|
|
|
3130 |
}#if end
|
|
|
3131 |
|
|
|
3132 |
#預設的 pgp 簽署方式
|
|
|
3133 |
$micalg="micalg=\"pgp-sha512\"";
|
|
|
3134 |
|
|
|
3135 |
#如果輸出結尾不是 "-----END PGP SIGNATURE-----"
|
|
|
3136 |
if($callShell["output"][count($callShell["output"])-1]!=="-----END PGP SIGNATURE-----"){
|
|
|
3137 |
|
|
|
3138 |
#設置錯誤識別
|
|
|
3139 |
$result["status"]="false";
|
|
|
3140 |
|
|
|
3141 |
#設置錯誤資訊
|
|
|
3142 |
$result["error"]=$callShell;
|
|
|
3143 |
|
|
|
3144 |
#回傳結果
|
|
|
3145 |
return $result;
|
|
|
3146 |
|
|
|
3147 |
}#if end
|
|
|
3148 |
|
|
|
3149 |
#初始化儲存 PGP SIGNATURE 字串
|
|
|
3150 |
$signDataOfGPG="";
|
|
|
3151 |
|
|
|
3152 |
#尚未到開始 PGP SIGNATURE 部分時
|
|
|
3153 |
while($callShell["output"][count($callShell["output"])-1]!=="-----BEGIN PGP SIGNATURE-----"){
|
|
|
3154 |
|
|
|
3155 |
#如果有資料了
|
|
|
3156 |
if(!empty($signDataOfGPG)){
|
|
|
3157 |
|
|
|
3158 |
#前面加上換行字元
|
|
|
3159 |
$signDataOfGPG="\r\n".$signDataOfGPG;
|
|
|
3160 |
|
|
|
3161 |
}#if end
|
|
|
3162 |
|
|
|
3163 |
#取得 PGP SIGNATURE 部分
|
|
|
3164 |
$signDataOfGPG=$callShell["output"][count($callShell["output"])-1].$signDataOfGPG;
|
|
|
3165 |
|
|
|
3166 |
#移除已經抓好的資料
|
|
|
3167 |
unset($callShell["output"][count($callShell["output"])-1]);
|
|
|
3168 |
|
|
|
3169 |
}#while end
|
|
|
3170 |
|
|
|
3171 |
#取得 PGP SIGNATURE 部分
|
|
|
3172 |
$signDataOfGPG="\r\n".$callShell["output"][count($callShell["output"])-1]."\r\n".$signDataOfGPG;
|
|
|
3173 |
|
|
|
3174 |
#head 增加表示有 GPG 簽署
|
|
|
3175 |
$head=$head."Security: GPG signed"."\r\n";
|
|
|
3176 |
|
|
|
3177 |
#函式說明:
|
|
|
3178 |
#建立以圖片(PNG格式)呈現的驗證碼.
|
|
|
3179 |
#回傳的解果:
|
|
|
3180 |
#$result["status"],執行是否正常,"true"代表執行成功,"false"代表執行失敗.
|
|
|
3181 |
#$result["error"],錯誤訊息.
|
|
|
3182 |
#$result["function"],檔前執行的函數名稱.
|
|
|
3183 |
#$result["randNumberWord"],傳驗證碼的內容.
|
|
|
3184 |
#$result["imgAddress"],包含src圖片的位置與名稱.
|
|
|
3185 |
#$result["imgSrcVal"],放在src裏面的圖片位置與名稱.
|
|
|
3186 |
#必填參數:
|
|
|
3187 |
#$conf["imgAddressAndName"],字串,爲驗證碼圖片儲存的位置與名稱,副檔名程式會自動產生
|
|
|
3188 |
$conf["authenticate::validationCode"]["imgAddressAndName"]="/tmp/xxx.png";
|
|
|
3189 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
3190 |
$conf["authenticate::validationCode"]["fileArgu"]=__FILE__;
|
|
|
3191 |
#可省略參數:
|
|
|
3192 |
#$conf["num"],字串,爲驗證碼的位數,請輸入阿拉伯數字,預設為"8"位數.
|
|
|
3193 |
#$conf["num"]="8";
|
|
|
3194 |
#$conf["disableImg"],字串,是否要取消驗證碼圖片的輸出,"true"為要取消,預設為"false"為不取消
|
|
|
3195 |
$conf["authenticate::validationCode"]["disableImg"]="true";
|
|
|
3196 |
#$conf["imgToData"],字串,預設為"true"代表將圖片轉存成base64圖片,並將原始圖片移除;反之為"false"
|
|
|
3197 |
#$conf["imgToData"]="true";
|
|
|
3198 |
#$conf["class"],字串,圖片要套用的css樣式類別.
|
|
|
3199 |
#$conf["class"]="";
|
|
|
3200 |
#$conf["content"],字串陣列,允許的亂數陣列內容,預設爲(1~9 and A~Z).
|
|
|
3201 |
#$conf["content"]=array();
|
|
|
3202 |
#參考資料:
|
|
|
3203 |
#無.
|
|
|
3204 |
#備註:
|
|
|
3205 |
#無.
|
|
|
3206 |
$validationCode=authenticate::validationCode($conf["authenticate::validationCode"]);
|
|
|
3207 |
unset($conf["authenticate::validationCode"]);
|
|
|
3208 |
|
|
|
3209 |
#如果檢查失敗
|
|
|
3210 |
if($validationCode["status"]==="false"){
|
|
|
3211 |
|
|
|
3212 |
#設置錯誤識別
|
|
|
3213 |
$result["status"]="false";
|
|
|
3214 |
|
|
|
3215 |
#設置錯誤訊息
|
|
|
3216 |
$result["error"]=$validationCode;
|
|
|
3217 |
|
|
|
3218 |
#回傳結果
|
|
|
3219 |
return $result;
|
|
|
3220 |
|
|
|
3221 |
}#if end
|
|
|
3222 |
|
|
|
3223 |
#初始化 boundary
|
|
|
3224 |
$boundary=$validationCode["randNumberWord"];
|
|
|
3225 |
|
|
|
3226 |
#初始化 boundary start
|
|
|
3227 |
$boundaryS="--".$boundary;
|
|
|
3228 |
|
|
|
3229 |
#初始化 boundary end
|
|
|
3230 |
$boundaryE=$boundaryS."--";
|
|
|
3231 |
|
|
|
3232 |
#將 data 用新的 boundary 包起來
|
|
|
3233 |
$data=$boundaryS."\r\n".$data."\r\n";
|
|
|
3234 |
|
|
|
3235 |
#8個空格
|
|
|
3236 |
$eightSpace=" ";
|
|
|
3237 |
|
|
|
3238 |
#描述內容為 gpg key 簽署的 head 資訊,"protocol"要空8格
|
|
|
3239 |
$gpgData="Content-Type: multipart/signed; ".$micalg.";"."\r\n".$eightSpace."protocol=\"application/pgp-signature\"; boundary=\"".$boundary."\"\r\n";
|
|
|
3240 |
|
|
|
3241 |
#增加描述用於 sign 的 gpg pub key
|
|
|
3242 |
$signDataOfGPG="Content-Type: application/pgp-signature; name=\"signature.asc\""."\r\n"."Content-Description: This is a digitally signed message part"."\r\n".$signDataOfGPG."\r\n";
|
|
|
3243 |
|
|
|
3244 |
#設置gpg key簽署的資訊
|
|
|
3245 |
$data=$data.$boundaryS."\r\n".$signDataOfGPG."\r\n".$boundaryE."\r\n";
|
|
|
3246 |
|
|
|
3247 |
#取得放置於head的Contet-Type描述
|
|
|
3248 |
$contentDescInHead=&$gpgData;
|
|
|
3249 |
|
|
|
3250 |
}#if end
|
|
|
3251 |
|
|
|
3252 |
#組合head與body,依據規定,每列不得大於70的字元
|
|
|
3253 |
$data=wordwrap($head.$contentDescInHead.$data,70,"\r\n",true);
|
|
|
3254 |
|
|
|
3255 |
#Send the DATA command to start message body
|
|
|
3256 |
if(\PEAR::isError($smtp->data($data))){
|
|
|
3257 |
|
|
|
3258 |
#設置錯誤識別
|
|
|
3259 |
$result["status"]="false";
|
|
|
3260 |
|
|
|
3261 |
#設置錯誤訊息
|
|
|
3262 |
$result["error"]="Unable to send data:".$data;
|
|
|
3263 |
|
|
|
3264 |
#回傳結果
|
|
|
3265 |
return $result;
|
|
|
3266 |
|
|
|
3267 |
}#if end
|
|
|
3268 |
|
|
|
3269 |
#使用完畢後要關閉連線
|
|
|
3270 |
$smtp->disconnect();
|
|
|
3271 |
|
|
|
3272 |
#設置執行正常
|
|
|
3273 |
$result["status"]="true";
|
|
|
3274 |
|
|
|
3275 |
#回傳結果
|
|
|
3276 |
return $result;
|
|
|
3277 |
|
|
|
3278 |
}#function pear_smtp_send end
|
|
|
3279 |
|
| 3 |
liveuser |
3280 |
}#class mail end
|
| 48 |
liveuser |
3281 |
|
|
|
3282 |
?>
|