| 48 |
liveuser |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
/*
|
|
|
4 |
|
|
|
5 |
QBPWCF, Quick Build PHP website Component base on Fedora Linux.
|
|
|
6 |
Copyright (C) 2014~2025 Min-Jhin,Chen
|
|
|
7 |
|
|
|
8 |
This file is part of QBPWCF.
|
|
|
9 |
|
|
|
10 |
QBPWCF is free software: you can redistribute it and/or modify
|
|
|
11 |
it under the terms of the GNU General Public License as published by
|
|
|
12 |
the Free Software Foundation, either version 3 of the License, or
|
|
|
13 |
(at your option) any later version.
|
|
|
14 |
|
|
|
15 |
QBPWCF is distributed in the hope that it will be useful,
|
|
|
16 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
17 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
18 |
GNU General Public License for more details.
|
|
|
19 |
|
|
|
20 |
You should have received a copy of the GNU General Public License
|
|
|
21 |
along with QBPWCF. If not, see <http://www.gnu.org/licenses/>.
|
|
|
22 |
|
|
|
23 |
*/
|
|
|
24 |
|
|
|
25 |
#使用命名空間qbpwcf
|
|
|
26 |
namespace qbpwcf;
|
|
|
27 |
|
|
|
28 |
#assets dir
|
|
|
29 |
$assetsDir="assets of form::mail::pear_smtp_send";
|
|
|
30 |
|
|
|
31 |
#get mail server
|
|
|
32 |
#函式說明:
|
|
|
33 |
#將固定格式的字串分開,並回傳分開的結果.
|
|
|
34 |
#回傳結果:
|
|
|
35 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
36 |
#$result["error"],錯誤訊息陣列
|
|
|
37 |
#$result["function"],當前執行的函數名稱.
|
|
|
38 |
#$result["argu"],使用的參數.
|
|
|
39 |
#$result["oriStr"],要分割的原始字串內容
|
|
|
40 |
#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
|
|
|
41 |
#$result["dataCounts"],爲總共分成幾段
|
|
|
42 |
#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
|
|
|
43 |
#必填參數:
|
|
|
44 |
#$conf["stringIn"],字串,要處理的字串.
|
|
|
45 |
$conf["stringProcess::spiltString"]["stringIn"]=systemMailAcct;
|
|
|
46 |
#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.
|
|
|
47 |
$conf["stringProcess::spiltString"]["spiltSymbol"]="@";
|
|
|
48 |
#可省略參數:
|
|
|
49 |
#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
|
|
|
50 |
#$conf["allowEmptyStr"]="false";
|
|
|
51 |
#參考資料:
|
|
|
52 |
#無.
|
|
|
53 |
#備註:
|
|
|
54 |
#無.
|
|
|
55 |
$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
|
|
|
56 |
unset($conf["stringProcess::spiltString"]);
|
|
|
57 |
|
|
|
58 |
#如果執行失敗
|
|
|
59 |
if($spiltString["status"]==="false"){
|
|
|
60 |
|
|
|
61 |
#函式說明:
|
|
|
62 |
#撰寫log
|
|
|
63 |
#回傳結果:
|
|
|
64 |
#$result["status"],狀態,"true"或"false".
|
|
|
65 |
#$result["error"],錯誤訊息陣列.
|
|
|
66 |
#$result["function"],當前函式的名稱.
|
|
|
67 |
#$result["argu"],使用的參數.
|
|
|
68 |
#必填參數:
|
|
|
69 |
#$conf["path"],字串,log檔案的路徑與名稱.
|
|
|
70 |
$conf["path"]=$logFile;
|
|
|
71 |
#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
|
|
|
72 |
$conf["content"]=$spiltString;
|
|
|
73 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
74 |
$conf["fileArgu"]=__FILE__;
|
|
|
75 |
#可省略參數:
|
|
|
76 |
#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
|
|
|
77 |
#$conf["rewrite"]="false";
|
|
|
78 |
#參考資料:
|
|
|
79 |
#無.
|
|
|
80 |
#備註:
|
|
|
81 |
#無.
|
|
|
82 |
$record=logs::record($conf);
|
|
|
83 |
unset($conf);
|
|
|
84 |
|
|
|
85 |
#如果寫log失敗
|
|
|
86 |
if($record["status"]==="false"){
|
|
|
87 |
|
|
|
88 |
#印出結果
|
|
|
89 |
var_dump($record);
|
|
|
90 |
|
|
|
91 |
}#if end
|
|
|
92 |
|
|
|
93 |
#結束執行,回傳錯誤代碼1
|
|
|
94 |
exit(1);
|
|
|
95 |
|
|
|
96 |
}#if end
|
|
|
97 |
|
|
|
98 |
#如果不是分成兩段
|
|
|
99 |
if($spiltString["dataCounts"]!==2){
|
|
|
100 |
|
|
|
101 |
#函式說明:
|
|
|
102 |
#撰寫log
|
|
|
103 |
#回傳結果:
|
|
|
104 |
#$result["status"],狀態,"true"或"false".
|
|
|
105 |
#$result["error"],錯誤訊息陣列.
|
|
|
106 |
#$result["function"],當前函式的名稱.
|
|
|
107 |
#$result["argu"],使用的參數.
|
|
|
108 |
#必填參數:
|
|
|
109 |
#$conf["path"],字串,log檔案的路徑與名稱.
|
|
|
110 |
$conf["path"]=$logFile;
|
|
|
111 |
#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
|
|
|
112 |
$conf["content"]=$spiltString;
|
|
|
113 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
114 |
$conf["fileArgu"]=__FILE__;
|
|
|
115 |
#可省略參數:
|
|
|
116 |
#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
|
|
|
117 |
#$conf["rewrite"]="false";
|
|
|
118 |
#參考資料:
|
|
|
119 |
#無.
|
|
|
120 |
#備註:
|
|
|
121 |
#無.
|
|
|
122 |
$record=logs::record($conf);
|
|
|
123 |
unset($conf);
|
|
|
124 |
|
|
|
125 |
#如果寫log失敗
|
|
|
126 |
if($record["status"]==="false"){
|
|
|
127 |
|
|
|
128 |
#印出結果
|
|
|
129 |
var_dump($record);
|
|
|
130 |
|
|
|
131 |
}#if end
|
|
|
132 |
|
|
|
133 |
#結束執行,回傳錯誤代碼1
|
|
|
134 |
exit(1);
|
|
|
135 |
|
|
|
136 |
}#if end
|
|
|
137 |
|
|
|
138 |
#函式說明:
|
|
|
139 |
#使用 php-pear-smtp 來透過SMTP伺服器寄信.
|
|
|
140 |
#回傳結果:
|
|
|
141 |
#$result["status"],執行正常與否,"true"代表正常;反之為"false".
|
|
|
142 |
#$result["error"],錯誤訊息陣列
|
|
|
143 |
#$result["function"],當前執行的函數.
|
|
|
144 |
#必填參數:
|
|
|
145 |
#$conf["mailServer"],字串,要使用的SMTP郵件伺服器網址.
|
|
|
146 |
$conf["mailServer"]="ssl://".$spiltString["dataArray"][1];
|
|
|
147 |
#$conf["username"],字串,用來登入郵件伺服器的帳號
|
|
|
148 |
$conf["username"]=$spiltString["dataArray"][0];
|
|
|
149 |
#$conf["password"],字串,用來登入郵件伺服器的密碼
|
|
|
150 |
$conf["password"]=systemMailPass;
|
|
|
151 |
#$conf["receiverMail"],陣列,收件人的信箱
|
|
|
152 |
$conf["receiverMail"]=array("liveuser@qbpwcf.org");
|
|
|
153 |
#$conf["subject"],字串,郵件的主題
|
|
|
154 |
$conf["subject"]="test send mail with pear net imap";
|
|
|
155 |
#$conf["plainBody"],字串,郵件本文的純文字內容.
|
|
|
156 |
$conf["plainBody"]="test send mail with pear net imap";
|
|
|
157 |
#$conf["htmlBody"]="";,字串,郵件本文的html內容,多媒體盡量不要用base64的方式來嵌入,因為大部分的郵件服務(Gmail)都不支援,如果是在單機上的郵件軟體就可能有支援,例如:Evolution.
|
|
|
158 |
$conf["htmlBody"]="<h1>test send mail with pear net imap</h1>";
|
|
|
159 |
#可省略參數:
|
|
|
160 |
#$conf["mailServerPort"],整數,smtp server的port,預設為465.
|
|
|
161 |
#$conf["mailServerPort"]=465;
|
|
|
162 |
#$conf["mailerMailDisplay"],字串,要顯示的寄件人信箱,預設爲 $conf["username"]
|
|
|
163 |
$conf["mailerMailDisplay"]="liveuser@qbpwcf.org";
|
|
|
164 |
#$conf["mailerNameDisplay"],字串,要顯示的寄件人姓名,預設爲 $conf["username"]
|
|
|
165 |
$conf["mailerNameDisplay"]="liveuser";
|
|
|
166 |
#$conf["receiverMailDisplay"],陣列,要顯示的收件人信箱,預設爲 $conf["receiverMail"] 對應的元素.
|
|
|
167 |
#$conf["receiverMailDisplay"]="";
|
|
|
168 |
#$conf["receiverNameDisplay"],陣列,要顯示的收件人姓名,預設爲 $conf["receiverMail"] 對應的元素.
|
|
|
169 |
$conf["receiverNameDisplay"]=array("liveuser");
|
|
|
170 |
#$conf["attachment"],陣列,每個要寄送的附件路徑與檔案名稱
|
|
|
171 |
#$conf["attachment"]=array();
|
|
|
172 |
#$conf["attachmentName"],陣列,每個要寄送的附件顯示名稱,預設為$conf["attachment"]中的實際檔案名稱.
|
|
|
173 |
#$conf["attachmentName"]=array();
|
|
|
174 |
#$conf["attachmentMimeType"],陣列,每個附件的 mimeType,預設為"application/*".
|
|
|
175 |
#$conf["attachmentMimeType"]array();
|
|
|
176 |
#$conf["userAgent"],字串,用於表示使用smtp服務的軟體資訊,預設為"Powerd by QBPWCF".
|
|
|
177 |
#$conf["userAgent"]="Powerd by QBPWCF";
|
|
|
178 |
#$conf["org"],字串,若要表示來源組織名稱,可在此設定.
|
|
|
179 |
$conf["org"]="北角網頁設計(https://www.qbpwcf.org)";
|
|
|
180 |
#$conf["notifyReceived"],字串,回報已讀通知,預設為"true"代表要;反之為"false".
|
|
|
181 |
#$conf["notifyReceived"]="true";
|
|
|
182 |
#$conf["signWithGPGid"],字串,用於簽署的gpg id,預設不使用.
|
|
|
183 |
#$conf["signWithGPGid"]="";
|
|
|
184 |
#參考資料:
|
|
|
185 |
#官網=>http://pear.php.net/package/Net_SMTP
|
|
|
186 |
#Document=>https://github.com/pear/Net_SMTP
|
|
|
187 |
#mail body boundary=>https://www.w3.org/Protocols/rfc1341/7_2_Multipart.html
|
|
|
188 |
#備註:
|
|
|
189 |
#需要php-pear-Net-SMTP
|
|
|
190 |
$pear_smtp_send=mail::pear_smtp_send($conf);
|
|
|
191 |
unset($conf);
|
|
|
192 |
|
|
|
193 |
#如果執行失敗
|
|
|
194 |
if($pear_smtp_send["status"]==="false"){
|
|
|
195 |
|
|
|
196 |
#函式說明:
|
|
|
197 |
#撰寫log
|
|
|
198 |
#回傳結果:
|
|
|
199 |
#$result["status"],狀態,"true"或"false".
|
|
|
200 |
#$result["error"],錯誤訊息陣列.
|
|
|
201 |
#$result["function"],當前函式的名稱.
|
|
|
202 |
#$result["argu"],使用的參數.
|
|
|
203 |
#必填參數:
|
|
|
204 |
#$conf["path"],字串,log檔案的路徑與名稱.
|
|
|
205 |
$conf["path"]=$logFile;
|
|
|
206 |
#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
|
|
|
207 |
$conf["content"]=$pear_smtp_send;
|
|
|
208 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
209 |
$conf["fileArgu"]=__FILE__;
|
|
|
210 |
#可省略參數:
|
|
|
211 |
#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
|
|
|
212 |
#$conf["rewrite"]="false";
|
|
|
213 |
#參考資料:
|
|
|
214 |
#無.
|
|
|
215 |
#備註:
|
|
|
216 |
#無.
|
|
|
217 |
$record=logs::record($conf);
|
|
|
218 |
unset($conf);
|
|
|
219 |
|
|
|
220 |
#如果寫log失敗
|
|
|
221 |
if($record["status"]==="false"){
|
|
|
222 |
|
|
|
223 |
#印出結果
|
|
|
224 |
var_dump($record);
|
|
|
225 |
|
|
|
226 |
}#if end
|
|
|
227 |
|
|
|
228 |
#結束執行,回傳錯誤代碼1
|
|
|
229 |
exit(1);
|
|
|
230 |
|
|
|
231 |
}#if end
|
|
|
232 |
|
|
|
233 |
?>
|