| 14 |
liveuser |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
#指派命名空間
|
|
|
4 |
namespace qbpwcf;
|
|
|
5 |
|
|
|
6 |
#匯入外部套件
|
|
|
7 |
include("../allInOne.php");
|
|
|
8 |
|
|
|
9 |
#說明正在測試的內容
|
|
|
10 |
echo"<hr>mail::mailTo - testCase 1";
|
|
|
11 |
|
|
|
12 |
/*
|
|
|
13 |
|
|
|
14 |
#涵式說明:
|
|
|
15 |
#用imap協定寄信
|
|
|
16 |
#回傳的變數:
|
|
|
17 |
#$result["status"],寄信的情況,"true"爲成功,"false"爲失敗.
|
|
|
18 |
#$result["error"],錯誤訊息陣列
|
|
|
19 |
#$result["function"],當前執行的函數
|
|
|
20 |
#必填的參數:
|
|
|
21 |
$conf["username"]="tcfxfzoi@gmail.com";#郵件服務的登入帳號
|
|
|
22 |
$conf["password"]="superfedoralinux";#郵件服務的登入密碼
|
|
|
23 |
$conf["receiver"]="tcfxfzoi@gmail.com";#收件着
|
|
|
24 |
$conf["subject"]="測試信件請勿回覆";#信件主旨
|
|
|
25 |
$conf["body"]="測試信件請勿回覆";#本文
|
|
|
26 |
#可省略的參數:
|
|
|
27 |
#$conf["mailServerPositionAndPort"]="";#郵件伺服器的網址與連接口,若省略則採用預設的gmail信箱
|
|
|
28 |
#$conf["headerInfo"]="";#表頭訊息,預設爲"From:".$conf["username"]."\r\n"."Reply-To:".$conf["receiver"]."\r\n";
|
|
|
29 |
#$conf["cc"]="";#信件的副本要寄給誰
|
|
|
30 |
#$conf["bcc"]="";#信件的密件副本要寄給誰,預設爲$conf["username"],以作爲備份。
|
|
|
31 |
#參考資料來源:
|
|
|
32 |
#http://www.php.net/manual/en/function.imap-mail.php
|
|
|
33 |
#http://www.php.net/manual/en/function.imap-errors.php
|
|
|
34 |
#http://www.php.net/manual/en/function.imap-alerts.php
|
|
|
35 |
#http://www.php.net/manual/en/function.imap-last-error.php
|
|
|
36 |
#http://wiki.dreamhost.com/PHP_IMAP#Verify_PHP_INI_Settings
|
|
|
37 |
var_dump(mail::mailTo($conf));
|
|
|
38 |
unset($conf);
|
|
|
39 |
|
|
|
40 |
*/
|
|
|
41 |
|
|
|
42 |
#說明正在測試的內容
|
|
|
43 |
echo"<hr>mail::curlSmtp - testCase 1";
|
|
|
44 |
|
|
|
45 |
/*
|
|
|
46 |
|
|
|
47 |
#圖片
|
|
|
48 |
#函數說明:
|
|
|
49 |
#用data:mimeType;base64,imgVar的形式來提供圖片的連結,亦即圖片儲存在變數裡面.
|
|
|
50 |
#回傳結果:
|
|
|
51 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
52 |
#$result["error"],錯誤訊息
|
|
|
53 |
#$result["content"],語法
|
|
|
54 |
#$result["function"],當前執行的函數名稱
|
|
|
55 |
#必填參數:
|
|
|
56 |
#$conf["imgPosition"],要轉存成2元碼的圖片檔案位置與名稱
|
|
|
57 |
$conf["imgPosition"]="mailT/這是測試用的圖片.png";
|
|
|
58 |
$conf["fileArgu"]=__FILE__;
|
|
|
59 |
#可省略參數:
|
|
|
60 |
#$conf["alt"],若沒有圖片要用什麼文字顯示。
|
|
|
61 |
#$conf["alt"]="";
|
|
|
62 |
#$conf["class"],圖片要套用的css樣式名稱.
|
|
|
63 |
#$conf["class"]="";
|
|
|
64 |
#$conf["mimeType"],2元碼的內容是什麼,預設為"image/png".
|
|
|
65 |
#$conf["mimeType"]="image/*";
|
|
|
66 |
#$conf["compressType"],2元碼壓縮的方式,預設為"base64".
|
|
|
67 |
#$conf["compressType"]="base64";
|
|
|
68 |
#$conf["delImg"],讀取完圖片檔案後,要移除圖片嗎?"true"代表要移除,"false"代表不要移除,預設為"false".
|
|
|
69 |
#$conf["delImg"]="false";
|
|
|
70 |
#參考資料:
|
|
|
71 |
#將檔案用字串變數儲存起來=>http://php.net/manual/en/function.file-get-contents.php
|
|
|
72 |
#壓縮2元碼=>http://php.net/manual/en/function.base64-encode.php
|
|
|
73 |
$img=img::data($conf);
|
|
|
74 |
unset($conf);
|
|
|
75 |
|
|
|
76 |
#如果將圖片轉換成 data:mimeType;base64,imgVar 的形式失敗
|
|
|
77 |
if($img["status"]=="false"){
|
|
|
78 |
|
|
|
79 |
#印出錯誤訊息
|
|
|
80 |
var_dump($img);
|
|
|
81 |
|
|
|
82 |
#停止執行
|
|
|
83 |
exit;
|
|
|
84 |
|
|
|
85 |
}#if end
|
|
|
86 |
|
|
|
87 |
#涵式說明:
|
|
|
88 |
#放置可以套用css樣式的圖片
|
|
|
89 |
#回傳的結果:
|
|
|
90 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
91 |
#$result["error"],錯誤訊息陣列
|
|
|
92 |
#$result["function"],當前函數執行的名稱
|
|
|
93 |
#$result["content"],印出圖片的語法。
|
|
|
94 |
#必填的參數:
|
|
|
95 |
$conf["position"]="https://start.fedoraproject.org/static/images/fedora-logo.png";#圖片位置
|
|
|
96 |
#可省略的參數:
|
|
|
97 |
#$conf["alt"]="";#若沒有圖片要用什麼文字顯示。
|
|
|
98 |
#$conf["class"]="";#要套用的css樣式類別名稱。
|
|
|
99 |
$fedoraLogo=img::show($conf);
|
|
|
100 |
unset($conf);
|
|
|
101 |
|
|
|
102 |
#如果放置圖片的語法
|
|
|
103 |
if($fedoraLogo["status"]=="false"){
|
|
|
104 |
|
|
|
105 |
#印出錯誤訊息
|
|
|
106 |
var_dump($fedoraLogo);
|
|
|
107 |
|
|
|
108 |
#停止執行
|
|
|
109 |
exit;
|
|
|
110 |
|
|
|
111 |
}#if end
|
|
|
112 |
|
|
|
113 |
#涵式說明:
|
|
|
114 |
#使用 curl 來透過SMTP伺服器寄信
|
|
|
115 |
#回傳的接結果:
|
|
|
116 |
#$result["status"],寄信的情況,若爲"true",則十之八九沒有問題.
|
|
|
117 |
#$result["error"],錯誤訊息陣列
|
|
|
118 |
#$result["function"],當前執行的函數
|
|
|
119 |
#$result["warning"],警示訊息,一些不會導致失敗但不能說是完美的問題.
|
|
|
120 |
#$result["output"],寄送信件時的處理訊息.
|
|
|
121 |
#$result["cmd"],寄信的語法
|
|
|
122 |
#必填的參數:
|
|
|
123 |
$conf["username"]="tcfxfzoi@gmail.com";#用來登入郵件伺服器的帳號
|
|
|
124 |
$conf["password"]="superfedoralinux";#用來登入郵件伺服器的密碼
|
|
|
125 |
$conf["receiverMail"]=array("tcfxfzoi@gmail.com","tcfxfzoi@hotmail.com","tcfxfzoi@yahoo.com.tw");#收件人的信箱
|
|
|
126 |
$conf["subject"]="系統測試";#郵件的主題
|
|
|
127 |
#$conf["plainBody"],字串,郵件本文的純文字內容.
|
|
|
128 |
$conf["plainBody"]="此爲測試信件可以忽略!";
|
|
|
129 |
#$conf["htmlBody"]="";,字串,郵件本文的html內容,多媒體盡量不要用base64的方式來嵌入,因為大部分的郵件服務(Gmail)都不支援,如果是在單機上的郵件軟體就可能有支援,例如:Evolution.
|
|
|
130 |
$conf["htmlBody"]="<h1>此爲測試信件可以忽略!</h1>\r\n".$img["content"];
|
|
|
131 |
#$conf["fileArgu"],字串,php內建變數「__FILE__」的內容.
|
|
|
132 |
$conf["fileArgu"]=__FILE__;
|
|
|
133 |
#可省略的參數:
|
|
|
134 |
#$conf["mailServer"]="";#要使用的SMTP郵件伺服器網址與連接口,預設爲 smtps://smtp.gmail.com:465
|
|
|
135 |
#$conf["mailerMailDisplay"]="";#要顯示的寄件人信箱,預設爲 $conf["username"]
|
|
|
136 |
#$conf["mailerNameDisplay"]="";#要顯示的寄件人姓名,預設爲 $conf["username"]
|
|
|
137 |
#$conf["receiverMailDisplay"]="";#要顯示的收件人信箱,預設爲 $conf["receiverMail"]
|
|
|
138 |
#$conf["receiverNameDisplay"]="";#要顯示的收件人姓名,預設爲 $conf["receiverMail"]
|
|
|
139 |
#$conf["attachment"],陣列,每個要寄送的附件路徑與檔案名稱
|
|
|
140 |
$conf["attachment"]=array("mailT/fedoraBear.png","mailT/fileAccessT.tar");
|
|
|
141 |
#$conf["attachmentName"],陣列,每個要寄送的附件顯示名稱,預設為$conf["attachment"]中的實際檔案名稱.
|
|
|
142 |
#$conf["attachmentName"]=array();
|
|
|
143 |
#$conf["attachmentMimeType"],陣列,每個附件的 mimeType,預設為"application/*".
|
|
|
144 |
#$conf["attachmentMimeType"]array();
|
|
|
145 |
#範例語句:
|
|
|
146 |
#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
|
|
|
147 |
#範例信件內容:
|
|
|
148 |
#From: "userName" <username@gmail.com>
|
|
|
149 |
#To: "receiverName" <userPassword@yahoo.com.tw>
|
|
|
150 |
#Subject: This is a test
|
|
|
151 |
#本文~
|
|
|
152 |
#參考資料來源:
|
|
|
153 |
#http://stackoverflow.com/questions/14722556/using-curl-to-send-email
|
|
|
154 |
var_dump(mail::curlSmtp($conf));
|
|
|
155 |
#mail::curlSmtp($conf);
|
|
|
156 |
unset($conf);
|
|
|
157 |
|
|
|
158 |
*/
|
|
|
159 |
|
|
|
160 |
#說明正在測試的內容
|
|
|
161 |
echo"<hr>mail::multiCurlSmtp - testCase 1";
|
|
|
162 |
|
|
|
163 |
/*
|
|
|
164 |
|
|
|
165 |
#涵式說明:
|
|
|
166 |
#使用 linux 的 curl 指令來透過SMTP伺服器寄大量不同內容的信件.
|
|
|
167 |
#回傳的接結果:
|
|
|
168 |
#$result["status"],寄信的情況,若爲"true",則十之八九沒有問題.
|
|
|
169 |
#$result["error"],錯誤訊息陣列
|
|
|
170 |
#$result["function"],當前執行的函數
|
|
|
171 |
#$result["warning"],警示訊息,一些不會導致失敗但不能說是完美的問題.
|
|
|
172 |
#$result["cmd"],寄信的指令.
|
|
|
173 |
#$result["detailCmd"],較詳細的寄信指令.
|
|
|
174 |
#必填的參數:
|
|
|
175 |
#$conf["username"],字串,用來登入郵件伺服器的帳號
|
|
|
176 |
$conf["username"]="tcfxfzoi@gmail.com";
|
|
|
177 |
#$conf["password"],字串,用來登入郵件伺服器的密碼
|
|
|
178 |
$conf["password"]="superfedoralinux";
|
|
|
179 |
#$conf["receiverMail"],二維字串陣列,每個信件的收件人信箱有哪些.
|
|
|
180 |
$conf["receiverMail"]=array(array("tcfxfzoi@gmail.com","tcfxfzoi@yahoo.com.tw","tcfxfzoi@hotmail.com"),array("tcfxfzoi@gmail.com","tcfxfzoi@yahoo.com.tw","tcfxfzoi@hotmail.com"),array("tcfxfzoi@gmail.com","tcfxfzoi@yahoo.com.tw","tcfxfzoi@hotmail.com"));
|
|
|
181 |
#$conf["subject"],字串陣列,每封郵件的主題.
|
|
|
182 |
$conf["subject"]=array("mail1","mail2","mail3");
|
|
|
183 |
#$conf["plainBody"],字串陣列,郵件本文的純文字內容.
|
|
|
184 |
$conf["plainBody"]=array("Hello world","Hello world","Hello world");
|
|
|
185 |
#$conf["htmlBody"]="";,字串陣列,郵件本文的html內容,多媒體盡量不要用base64的方式來嵌入,因為大部分的郵件服務(Gmail)都不支援,如果是在單機上的郵件軟體就可能有支援,例如:Evolution.
|
|
|
186 |
$conf["htmlBody"]=array("<div style=\"color:red\">Hello World</div>","<div style=\"color:red\">Hello World</div>","<div style=\"color:red\">Hello World</div>");
|
|
|
187 |
#$conf["fileArgu"],字串,php內建變數「__FILE__」的內容.
|
|
|
188 |
$conf["fileArgu"]=__FILE__;
|
|
|
189 |
#可省略的參數:
|
|
|
190 |
#$conf["mailServer"],字串,要使用的SMTP郵件伺服器網址與連接口,預設爲 smtps://smtp.gmail.com:465
|
|
|
191 |
#$conf["mailServer"]="";
|
|
|
192 |
#$conf["mailerMailDisplay"],字串,要顯示的寄件人信箱,預設爲 $conf["username"]
|
|
|
193 |
#$conf["mailerMailDisplay"]="";
|
|
|
194 |
#$conf["mailerNameDisplay"],字串,要顯示的寄件人姓名,預設爲 $conf["username"]
|
|
|
195 |
#$conf["mailerNameDisplay"]="";
|
|
|
196 |
#$conf["receiverMailDisplay"],陣列,每封信要顯示的收件人信箱,預設爲 $conf["receiverMail"] 對應的元素.
|
|
|
197 |
#$conf["receiverMailDisplay"]=array("");
|
|
|
198 |
#$conf["receiverNameDisplay"],陣列,每封信要顯示的收件人姓名,預設爲 $conf["receiverMail"] 對應的元素.
|
|
|
199 |
#$conf["receiverNameDisplay"]=array("");
|
|
|
200 |
#$conf["attachment"],二維陣列,每個信件要寄送的附件路徑與檔案名稱
|
|
|
201 |
$conf["attachment"]=array(array("fileAccessT.tar","fedoraBear.png","資館周行前會資建股報告.swf"),array("fileAccessT.tar","fedoraBear.png","資館周行前會資建股報告.swf"),array("fileAccessT.tar","fedoraBear.png","資館周行前會資建股報告.swf"));
|
|
|
202 |
#$conf["attachmentName"],二維陣列,每個信件要寄送的附件顯示名稱,預設為$conf["attachment"]中的實際檔案名稱.
|
|
|
203 |
#$conf["attachmentName"]=array(array());
|
|
|
204 |
#$conf["attachmentMimeType"],二維陣列,每個信件附件的 mimeType,預設為"application/*".
|
|
|
205 |
#$conf["attachmentMimeType"]array(array());
|
|
|
206 |
#備註:
|
|
|
207 |
#建構中...
|
|
|
208 |
var_dump(mail::multiCurlSmtp($conf));
|
|
|
209 |
unset($conf);
|
|
|
210 |
|
|
|
211 |
*/
|
|
|
212 |
|
|
|
213 |
#說明正在測試的內容
|
|
|
214 |
echo"<hr>mail::multiCurlSmtp - testCase 2";
|
|
|
215 |
|
|
|
216 |
/*
|
|
|
217 |
|
|
|
218 |
#涵式說明:
|
|
|
219 |
#使用 linux 的 curl 指令來透過SMTP伺服器寄大量不同內容的信件.
|
|
|
220 |
#回傳的接結果:
|
|
|
221 |
#$result["status"],寄信的情況,若爲"true",則十之八九沒有問題.
|
|
|
222 |
#$result["error"],錯誤訊息陣列
|
|
|
223 |
#$result["function"],當前執行的函數
|
|
|
224 |
#$result["warning"],警示訊息,一些不會導致失敗但不能說是完美的問題.
|
|
|
225 |
#$result["cmd"],寄信的指令.
|
|
|
226 |
#$result["detailCmd"],較詳細的寄信指令.
|
|
|
227 |
#必填的參數:
|
|
|
228 |
#$conf["username"],字串,用來登入郵件伺服器的帳號
|
|
|
229 |
$conf["username"]="jeff_chen@handlink.com.tw";
|
|
|
230 |
#$conf["password"],字串,用來登入郵件伺服器的密碼
|
|
|
231 |
$conf["password"]="16363914";
|
|
|
232 |
#$conf["receiverMail"],二維字串陣列,每個信件的收件人信箱有哪些.
|
|
|
233 |
$conf["receiverMail"]=array(array("jeff_chen@handlink.com.tw","tcfxfzoi@gmail.com","jeffcheninhl@gmail.com"));
|
|
|
234 |
#$conf["subject"],字串陣列,每封郵件的主題.
|
|
|
235 |
$conf["subject"]=array("mail");
|
|
|
236 |
#$conf["plainBody"],字串陣列,郵件本文的純文字內容.
|
|
|
237 |
$conf["plainBody"]=array("Hello world");
|
|
|
238 |
#$conf["htmlBody"]="";,字串陣列,郵件本文的html內容,多媒體盡量不要用base64的方式來嵌入,因為大部分的郵件服務(Gmail)都不支援,如果是在單機上的郵件軟體就可能有支援,例如:Evolution.
|
|
|
239 |
$conf["htmlBody"]=array("<div style=\"color:red\">Hello World</div>");
|
|
|
240 |
#$conf["fileArgu"],字串,php內建變數「__FILE__」的內容.
|
|
|
241 |
$conf["fileArgu"]=__FILE__;
|
|
|
242 |
#可省略的參數:
|
|
|
243 |
#$conf["usernameOnly"],字串,登入的帳號是否只要名稱不要@,預設爲"false"使用完整名稱跟@;反之爲"false".
|
|
|
244 |
$conf["usernameOnly"]="true";
|
|
|
245 |
#$conf["mailServer"],字串,要使用的SMTP郵件伺服器網址與連接口,預設爲 smtps://smtp.gmail.com:465
|
|
|
246 |
$conf["mailServer"]="smtps://mail.handlink.com.tw:465";
|
|
|
247 |
#$conf["mailerMailDisplay"],字串,要顯示的寄件人信箱,預設爲 $conf["username"]
|
|
|
248 |
#$conf["mailerMailDisplay"]="";
|
|
|
249 |
#$conf["mailerNameDisplay"],字串,要顯示的寄件人姓名,預設爲 $conf["username"]
|
|
|
250 |
#$conf["mailerNameDisplay"]="";
|
|
|
251 |
#$conf["receiverMailDisplay"],陣列,每封信要顯示的收件人信箱,預設爲 $conf["receiverMail"] 對應的元素.
|
|
|
252 |
#$conf["receiverMailDisplay"]=array("");
|
|
|
253 |
#$conf["receiverNameDisplay"],陣列,每封信要顯示的收件人姓名,預設爲 $conf["receiverMail"] 對應的元素.
|
|
|
254 |
#$conf["receiverNameDisplay"]=array("");
|
|
|
255 |
#$conf["attachment"],二維陣列,每個信件要寄送的附件路徑與檔案名稱
|
|
|
256 |
$conf["attachment"]=array(array("fileAccessT.tar","fedoraBear.png","資館周行前會資建股報告.swf"),array("fileAccessT.tar","fedoraBear.png","資館周行前會資建股報告.swf"),array("fileAccessT.tar","fedoraBear.png","資館周行前會資建股報告.swf"));
|
|
|
257 |
#$conf["attachmentName"],二維陣列,每個信件要寄送的附件顯示名稱,預設為$conf["attachment"]中的實際檔案名稱.
|
|
|
258 |
#$conf["attachmentName"]=array(array());
|
|
|
259 |
#$conf["attachmentMimeType"],二維陣列,每個信件附件的 mimeType,預設為"application/*".
|
|
|
260 |
#$conf["attachmentMimeType"]array(array());
|
|
|
261 |
#$conf["insecure"],字串,是否允許不安全的tls連線,預設爲"false"不允許,"true"爲允許.
|
|
|
262 |
$conf["insecure"]="true";
|
|
|
263 |
#備註:
|
|
|
264 |
#建構中...
|
|
|
265 |
var_dump(mail::multiCurlSmtp($conf));
|
|
|
266 |
unset($conf);
|
|
|
267 |
|
|
|
268 |
*/
|
|
|
269 |
|
|
|
270 |
#說明正在測試的內容
|
|
|
271 |
echo"<hr>mail::sendMail - testCase 1";
|
|
|
272 |
|
|
|
273 |
/*
|
|
|
274 |
|
|
|
275 |
#函式說明:
|
|
|
276 |
#透過php的mail函數寄信
|
|
|
277 |
#回傳內容:
|
|
|
278 |
#
|
|
|
279 |
#必填參數:
|
|
|
280 |
#
|
|
|
281 |
#可省略參數:
|
|
|
282 |
#
|
|
|
283 |
#參考資料來源:
|
|
|
284 |
#mail=>http://php.net/manual/en/function.mail.php
|
|
|
285 |
#Internet Message Format=>http://www.faqs.org/rfcs/rfc2822.html
|
|
|
286 |
#備註:
|
|
|
287 |
#建構中
|
|
|
288 |
var_dump(mail::sendMail());
|
|
|
289 |
|
|
|
290 |
*/
|
|
|
291 |
|
|
|
292 |
?>
|