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

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