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

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