• R/O
  • SSH
  • HTTPS

petitwork: 提交


Commit MetaInfo

修訂20 (tree)
時間2009-09-14 11:38:25
作者simizu001

Log Message

qdmail追加

Change Summary

差異

--- trunk/petitwork/petitwork/util/class/xbpwMail.php (revision 19)
+++ trunk/petitwork/petitwork/util/class/xbpwMail.php (revision 20)
@@ -16,13 +16,27 @@
1616 * @version svn:$Id$
1717 * @copyright 2007-2008 Exbridge,Inc.
1818 */
19+define("PW_MAIL_PROTOCOL_SMTP", "SMTP");
20+define("PW_MAIL_PROTOCOL_POP_BEFORE", "POP_BEFORE");
21+
1922 class xbpwMail
2023 {
2124 var $_pw_host = '127.0.0.1';
2225 var $_pw_port = '25';
26+ var $_pw_protocol = PW_MAIL_PROTOCOL_SMTP;
2327
24- //1:Pearライブラリ使用(SMTP設定が使用できるときに使う)
25- //2:php標準メール関数使用
28+ var $_pw_pop_host = '';
29+ var $_pw_pop_user = '';
30+ var $_pw_pop_password = '';
31+
32+ //1:pearを使用(POP認証ありサーバー 直接、配送先のSMTPサーバーに接続する方法)
33+ //
34+ //qdmail (高機能日本語メール送信ライブラリ・文字化けフリー http://hal456.net/qdmail/)
35+ //2:qdmailを使用(POP認証なしのSMTP設定が使用できるときに使う) http://hal456.net/qdmail/smtp_method(※直接、配送先のSMTPサーバーに接続する方法 が未実装)
36+ //3:qdmailを使用(easyText設定が使用できるときに使う)
37+ //
38+ //4:php標準メール関数使用
39+
2640 var $_pw_type = 1;
2741
2842 var $_pw_sender;
@@ -41,7 +55,7 @@
4155 * Creates new instance.
4256 * @access public
4357 */
44- function xbpwMail($host, $port, $type)
58+ function xbpwMail($host, $port, $type, $protocol = PW_MAIL_PROTOCOL_SMTP)
4559 {
4660 if (isset($host) || !is_null($host) || $host!='') {
4761 $this->_pw_host = $host;
@@ -52,9 +66,37 @@
5266 if (isset($type) || !is_null($type) || $type!='') {
5367 $this->_pw_type = $type;
5468 }
69+ $this->_pw_protocol = $protocol;
5570 }
5671
5772 /**
73+ * Setting pop host
74+ * @access public
75+ */
76+ function setPopHost($pop_host)
77+ {
78+ $this->_pw_pop_host = $pop_host;
79+ }
80+
81+ /**
82+ * Setting pop host
83+ * @access public
84+ */
85+ function setPopUser($pop_user)
86+ {
87+ $this->_pw_pop_user = $pop_user;
88+ }
89+
90+ /**
91+ * Setting pop host
92+ * @access public
93+ */
94+ function setPopPassword($pop_password)
95+ {
96+ $this->_pw_pop_password = $pop_password;
97+ }
98+
99+ /**
58100 * Setting mail sender
59101 * ex1) demo@mail.com
60102 * ex2) Mr.Demo <demo@mail.com>
@@ -144,7 +186,13 @@
144186 */
145187 function setSubject($subject)
146188 {
147- $this->_pw_subject = "=?ISO-2022-JP?B?" . base64_encode(mb_convert_encoding($subject, 'ISO-2022-JP', PW_ENCODE)) . "?=";
189+ if($this->_pw_type == 1){
190+ $this->_pw_subject = "=?ISO-2022-JP?B?" . base64_encode(mb_convert_encoding($subject, 'ISO-2022-JP', PW_ENCODE)) . "?=";
191+ }
192+ else {
193+ //$this->_pw_subject = mb_convert_encoding($subject, 'ISO-2022-JP', PW_ENCODE);
194+ $this->_pw_subject = $subject;
195+ }
148196 }
149197
150198 /**
@@ -176,6 +224,10 @@
176224 {
177225 if($this->_pw_type == 1){
178226 return $this->pearSendMail();
227+ }else if($this->_pw_type == 2){
228+ return $this->qdmailSendMailSMTP();
229+ }else if($this->_pw_type == 3){
230+ return $this->qdmailSendMaileasyText();
179231 }
180232 else{
181233 return $this->phpSendMail();
@@ -183,6 +235,128 @@
183235 }
184236
185237 /**
238+ * qdmail send mail(smtp)
239+ * @access public
240+ */
241+ function qdmailSendMailSMTP()
242+ {
243+ require_once(PW_VENDORS_DIR . DS . 'qdsmtp' . DS . 'qdsmtp.php');
244+ require_once(PW_VENDORS_DIR . DS . 'qdmail' . DS . 'qdmail.php');
245+
246+ //create instance
247+ $mail = & new Qdmail();
248+
249+ //setting smtp
250+ $mail -> smtp(true);
251+
252+ switch ($this->_pw_protocol) {
253+ case PW_MAIL_PROTOCOL_POP_BEFORE:
254+ $param = array(
255+ 'host' => $this->_pw_host,
256+ 'port' => $this->_pw_port,
257+ 'from' => $this->_pw_replyto,
258+ 'protocol' => 'POP_BEFORE',
259+ 'pop_host' => $this->_pw_pop_host,
260+ 'pop_user' => $this->_pw_pop_user,
261+ 'pop_pass' => $this->_pw_pop_password
262+ );
263+ break;
264+ default :
265+ $param = array(
266+ 'host' => $this->_pw_host,
267+ 'port' => $this->_pw_port,
268+ 'from' => $this->_pw_replyto,
269+ 'protocol' => 'SMTP'
270+ );
271+ break;
272+ }
273+ $mail -> smtpServer($param);
274+
275+ //setting sender
276+ $mail -> from($this->_pw_sender);
277+
278+ //setting reply-to
279+ if (isset($this->_pw_replyto)) {
280+ $mail -> to($this->_pw_replyto);
281+ }
282+
283+ //setting subject
284+ $mail -> subject($this->_pw_subject);
285+
286+ //setting body
287+ $mail -> text($this->_pw_body);
288+
289+ //adding to
290+ for ($i=0; $i<count($this->_pw_to); $i++) {
291+ $to[] = array($this->_pw_to[$i]);
292+ }
293+ $mail -> to( $to );
294+
295+ //adding cc
296+ for ($i=0; $i<count($this->_pw_cc); $i++) {
297+ $cc[] = array($this->_pw_cc[$i]);
298+ }
299+ $mail -> cc( $cc );
300+
301+ //adding bcc
302+ for($i=0; $i<count($this->_pw_bcc); $i++) {
303+ $bcc[] = array($this->_pw_bcc[$i]);
304+ }
305+ $mail -> bcc( $bcc );
306+
307+ //adding tempfile
308+ for ($i=0; $i<count($this->_pw_file); $i++) {
309+ $attach[] = array(
310+ 'PATH' => $this->_pw_file[$i],
311+ 'NAME' => $this->_pw_fname[$i],
312+ 'CONTENT-TYPE' => 'application/octet-stream'
313+ );
314+ }
315+ $mail -> attach ( $attach );
316+
317+ $return_flag = $mail -> send();
318+ return $return_flag;
319+ }
320+
321+ /**
322+ * qdmail send mail(easyText)
323+ * @access public
324+ */
325+ function qdmailSendMaileasyText()
326+ {
327+ require_once(PW_VENDORS_DIR . DS . 'qdmail' . DS . 'qdmail.php');
328+
329+ //create instance
330+ $mail = & new Qdmail();
331+
332+ //adding from
333+ $var['from'] = $this->_pw_sender;
334+ $var['reply-to'] = $this->_pw_replyto;
335+ $var['Return-Path'] = $this->_pw_replyto;
336+
337+ //adding to
338+ for ($i=0; $i<count($this->_pw_to); $i++) {
339+ $to[] = array($this->_pw_to[$i]);
340+ }
341+
342+ //adding tempfile
343+ for ($i=0; $i<count($this->_pw_file); $i++) {
344+ $attach[] = array( $this->_pw_file[$i], $this->_pw_fname[$i]);
345+ }
346+
347+ //setting smtp
348+ $mail -> easyText(
349+ $to, //setting to
350+ $this->_pw_subject, //setting subject
351+ $this->_pw_body, //setting body
352+ $var, //setting sender replyto
353+ $attach //setting tempfile
354+ );
355+
356+ return true;
357+ }
358+
359+ /**
186360 * pear send mail
187361 * @access public
188362 */
Show on old repository browser