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

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