source: branches/dev/html/admin/mail/sendmail.php @ 13621

Revision 13621, 8.2 KB checked in by nakanishi, 19 years ago (diff)
Line 
1<?php
2/*
3 * Copyright(c) 2000-2007 LOCKON CO.,LTD. All Rights Reserved.
4 *
5 * http://www.lockon.co.jp/
6 */
7$include_dir = realpath(dirname( __FILE__));
8require_once($include_dir."/../require.php");
9$conn = new SC_DbConn();
10$objSite = new SC_SiteInfo($conn);
11
12if(MELMAGA_SEND != true) {
13    exit;
14}
15
16//¥ê¥¢¥ë¥¿¥¤¥àÇÛ¿®¥â¡¼¥É¤¬¥ª¥ó¤Î¤È¤­
17if($_GET['mode'] == 'now') {
18    //----¡¡Ì¤Á÷¿®¥Ç¡¼¥¿¤ò¼èÆÀ¤¹¤ë
19    $time_data = $conn->getAll( "SELECT send_id FROM dtb_send_history  WHERE complete_count = 0 AND del_flg = 0 ORDER BY send_id ASC, start_date ASC" );
20} else {
21   
22    // postgresql ¤È mysql ¤È¤ÇSQL¤ò¤ï¤±¤ë
23    if (DB_TYPE == "pgsql") {
24        $sql = "SELECT send_id FROM dtb_send_history  ";
25        $sql.= "WHERE start_date  BETWEEN current_timestamp + '- 5 minutes' AND current_timestamp + '5 minutes' AND del_flg = 0 ORDER BY send_id ASC, start_date ASC";
26    }else if (DB_TYPE == "mysql") {
27        $sql = "SELECT send_id FROM dtb_send_history  ";
28        $sql.= "WHERE start_date  BETWEEN date_add(now(),INTERVAL -5 minute) AND date_add(now(),INTERVAL 5 minute) AND del_flg = 0 ORDER BY send_id ASC, start_date ASC";
29    }   
30    //----¡¡30ʬËè¤ËCron¤¬Á÷¿®»þ´Ö¥Ç¡¼¥¿³Îǧ
31    $time_data = $conn->getAll($sql);
32}
33
34//̤Á÷¿®¥á¡¼¥ë¤Î¿ô
35$count = count($time_data);
36
37//̤Á÷¿®¥á¡¼¥ë¤¬¤¢¤ì¤ÐÁ÷¿®½èÍý¤ò³¤±¤ë¡£¤Ê¤±¤ì¤ÐÃæÃǤ¹¤ë¡£
38if( $count > 0 ){
39    print("start sending <br />\n");
40} else {
41    print("not found <br />\n");
42    exit;
43}
44
45//---- ¥á¡¼¥ëÁ÷¿®½àÈ÷
46for( $i = 0; $i < $count; $i++ ) {
47
48    $sql = "SELECT * FROM dtb_send_customer WHERE send_id = ? AND (send_flag = 2 OR send_flag IS NULL)";
49    $list_data[] = $conn->getAll( $sql, array( $time_data[$i]["send_id"] ) );
50   
51    print_r($list_data);
52   
53    $sql = "SELECT * FROM dtb_send_history WHERE send_id = ?";
54    $mail_data[] = $conn->getAll( $sql, array( $time_data[$i]["send_id"] ) );
55   
56}
57
58//---- Á÷¿®·ë²Ì¥Õ¥é¥°ÍÑSQL
59$sql_flag ="UPDATE dtb_send_customer SET send_flag = ? WHERE send_id = ? AND customer_id = ?";
60$objMail = new GC_SendMail();
61
62
63
64//----¡¡¥á¡¼¥ëÀ¸À®¤ÈÁ÷¿®
65for( $i = 0; $i < $count; $i++ ) {
66
67    for( $j = 0; $j < count( $list_data[$i] ); $j ++ ) {
68
69        $customerName = "";
70        $mailBody = "";
71        $sendFlag = "";
72
73        //-- ¸ÜµÒ̾¤ÎÊÑ´¹
74        $name = trim($list_data[$i][$j]["name"]);
75       
76        if ($name == "") {
77            $name = "¤ªµÒ";
78        }
79       
80        $customerName = htmlspecialchars($name);
81        $subjectBody = ereg_replace( "{name}", $customerName , $mail_data[$i][0]["subject"] );
82        $mailBody = ereg_replace( "{name}", $customerName ,  $mail_data[$i][0]["body"] );
83
84
85        //-- ¥á¥ë¥Þ¥¬ÇÛ¿®¤ò¥Ö¥ì¥¤¥óÏ¢·È¤Ç¹Ô¤¦¾ì¹ç
86        if(MELMAGA_SEND_BLAYN){
87           
88            //-- ʸ»ú¤òÆüËܸì¤ËÀßÄê
89            Mb_language( "Japanese" );
90                 
91            //-- Á÷¿®¤¹¤ë¥á¡¼¥ë¤ÎÆâÍÆ¤ÈÁ÷¿®Àè
92            $sendResut = array(
93                          "to" => $list_data[$i][$j]["email"]        //¡¡¸ÜµÒ°¸Àè
94                    ,"subject" => mb_encode_mimeheader($subjectBody) //¡¡Subject 
95                       ,"from" => $objSite->data["email03"]          //¡¡Á÷¿®¸µ¥á¡¼¥ë¥¢¥É¥ì¥¹
96                  ,"replay_to" => $objSite->data["email03"]          //¡¡reply_to
97                ,"return_path" => $objSite->data["email04"]          //¡¡return_path
98                                                                       );
99            //-- ¥á¥Ã¥»¡¼¥¸¤Î¹½ÃÛ
100            $html_param['head_charset'] = "ISO-2022-JP";
101            $html_param['html_encoding'] = "ISO-2022-JP";
102            $html_param['html_charset'] = "JIS";
103           
104            //-- ¥Ö¥ì¥¤¥óSMTP¥µ¡¼¥Ð¡¼IP¥¢¥É¥ì¥¹
105            $param = array(   
106                       'host' => SMTP_HOST_BLAYN
107                      ,'port' => SMTP_PORT_BLAYN                 
108                                                  );
109            //-- Mail_mime¥ª¥Ö¥¸¥§¥¯¥ÈºîÀ®
110            $mail_mimeObj = new Mail_mime();
111           
112            //-- Mail_mime¥ª¥Ö¥¸¥§¥¯¥È¤ËHTML¤ÎËÜʸ¤òÄɲÃ
113            $mailBody = mb_convert_encoding($mailBody, "JIS", CHAR_CODE);
114            $mail_mimeObj->setHTMLBody($mailBody);
115           
116            $body = $mail_mimeObj->get($html_param);
117            $header = $mail_mimeObj->headers($sendResut);
118           
119            //-- PEAR::Mail¤ò»È¤Ã¤Æ¥á¡¼¥ëÁ÷¿®¥ª¥Ö¥¸¥§¥¯¥ÈºîÀ®
120            $mailObj =& Mail::factory("smtp", $param);
121            // ¥á¡¼¥ëÁ÷¿®
122            $result = $mailObj->send($sendResut["to"], $header, $body);
123
124        } else {
125            //-- ¥Æ¥­¥¹¥È¥á¡¼¥ëÇÛ¿®¤Î¾ì¹ç
126            if( $mail_data[$i][0]["mail_method"] == 2 ) {
127
128                $sendResut = MAIL_SENDING(
129                                         $list_data[$i][$j]["email"]                //¡¡¸ÜµÒ°¸Àè
130                                        ,$subjectBody                               //¡¡Subject
131                                        ,$mailBody                                  //¡¡¥á¡¼¥ëËÜʸ
132                                        ,$objSite->data["email03"]                  //¡¡Á÷¿®¸µ¥á¡¼¥ë¥¢¥É¥ì¥¹
133                                        ,$objSite->data["company_name"]             //¡¡Á÷¿®¸µÌ¾
134                                        ,$objSite->data["email03"]                  //¡¡reply_to
135                                        ,$objSite->data["email04"]                  //¡¡return_path
136                                        ,$objSite->data["email04"]                  //¡¡errors_to
137                                                                         );
138                                                                         
139
140            //--  HTML¥á¡¼¥ëÇÛ¿®¤Î¾ì¹ç 
141            } elseif( $mail_data[$i][0]["mail_method"] == 1 || $mail_data[$i][0]["mail_method"] == 3) {
142           
143                $sendResut = HTML_MAIL_SENDING(
144                                             $list_data[$i][$j]["email"]
145                                            ,$subjectBody
146                                            ,$mailBody
147                                            ,$objSite->data["email03"]                  //¡¡Á÷¿®¸µ¥á¡¼¥ë¥¢¥É¥ì¥¹
148                                            ,$objSite->data["company_name"]             //¡¡Á÷¿®¸µÌ¾
149                                            ,$objSite->data["email03"]                  //¡¡reply_to
150                                            ,$objSite->data["email04"]                  //¡¡return_path
151                                            ,$objSite->data["email04"]                  //¡¡errors_to
152                                                                     );
153            }
154        }
155 
156        //-- Á÷¿®´°Î»¤Ê¤é1¡¢¼ºÇԤʤé-1¤ò¥á¡¼¥ëÁ÷¿®·ë²Ì¥Õ¥é¥°¤È¤·¤ÆDB¤ËÁÞÆþ
157        if( ! $sendResut ){
158            $sendFlag = "-1";
159        } else {
160            $sendFlag = "1";
161           
162            // ´°Î»¤ò 1 Áý¤ä¤¹
163            $sql = "UPDATE dtb_send_history SET complete_count = complete_count + 1 WHERE send_id = ?";
164            $conn->query( $sql, array($mail_data[$i][0]["send_id"]));
165        }
166
167        $conn->query( $sql_flag, array( $sendFlag, $mail_data[$i][0]["send_id"], $list_data[$i][$j]["customer_id"] ) );
168       
169       
170
171    }
172
173    //--- ¥á¡¼¥ëÁ´·ïÁ÷¿®´°Î»¸å¤Î½èÍý
174    $completeSql = "UPDATE dtb_send_history SET end_date = now() WHERE send_id = ?";
175    $conn->query( $completeSql, array( $time_data[$i]["send_id"] ) );
176
177    //---¡¡Á÷¿®´°Î»¡¡Êó¹ð¥á¡¼¥ë
178    $compData =  date("Yǯm·îdÆüH»þiʬ" . "  ²¼µ­¥á¡¼¥ë¤ÎÇÛ¿®¤¬´°Î»¤·¤Þ¤·¤¿¡£" );
179
180    HTML_MAIL_SENDING(
181                     $objSite->data["email03"] 
182                    ,$compData
183                    ,$mail_data[$i][0]["body"]
184                    ,$objSite->data["email03"]                  //¡¡Á÷¿®¸µ¥á¡¼¥ë¥¢¥É¥ì¥¹
185                    ,$objSite->data["company_name"]             //¡¡Á÷¿®¸µÌ¾
186                    ,$objSite->data["email03"]                  //¡¡reply_to
187                    ,$objSite->data["email04"]                  //¡¡return_path
188                    ,$objSite->data["email04"]                  //¡¡errors_to
189                 );
190               
191    if ($_GET['mode'] = "now") {
192        header("Location: " . URL_DIR . "admin/mail/history.php");
193    }
194    echo "complete\n";
195
196}
197
198
199//--- ¥Æ¥­¥¹¥È¥á¡¼¥ëÇÛ¿®
200function MAIL_SENDING( $to, $subject, $body, $fromaddress, $from_name, $reply_to, $return_path, $errors_to="", $bcc="", $cc ="" ) {
201
202    $mail_obj = new GC_SendMail(); 
203    $mail_obj->setItem( $to, $subject, $body, $fromaddress, $from_name, $reply_to, $return_path, $errors_to, $bcc, $cc );
204       
205    if( $mail_obj->sendMail() ) {
206        return true;
207    }
208   
209}
210
211//--- HTML¥á¡¼¥ëÇÛ¿®
212function HTML_MAIL_SENDING( $to, $subject, $body, $fromaddress, $from_name, $reply_to, $return_path, $errors_to="", $bcc="", $cc ="" ) {
213
214    $html_mail_obj = new GC_SendMail();
215    $html_mail_obj->setItemHtml( $to, $subject, $body, $fromaddress, $from_name, $reply_to, $return_path, $errors_to, $bcc, $cc );
216           
217    if( $html_mail_obj->sendHtmlMail() ) {
218        return true;   
219    }
220   
221}
222
223
224?>
Note: See TracBrowser for help on using the repository browser.