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

Revision 13378, 8.2 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
38echo $count;
39exit;
40
41if( $count > 0 ){
42    print("start sending <br />\n");
43} else {
44    print("not found <br />\n");
45    exit;
46}
47
48//---- ¥á¡¼¥ëÁ÷¿®½àÈ÷
49for( $i = 0; $i < $count; $i++ ) {
50
51    $sql = "SELECT * FROM dtb_send_customer WHERE send_id = ? AND (send_flag = 2 OR send_flag IS NULL)";
52    $list_data[] = $conn->getAll( $sql, array( $time_data[$i]["send_id"] ) );
53   
54    $sql = "SELECT * FROM dtb_send_history WHERE send_id = ?";
55    $mail_data[] = $conn->getAll( $sql, array(  $time_data[$i]["send_id"] ) );
56
57}
58
59//---- Á÷¿®·ë²Ì¥Õ¥é¥°ÍÑSQL
60$sql_flag ="UPDATE dtb_send_customer SET send_flag = ? WHERE send_id = ? AND customer_id = ?";
61$objMail = new GC_SendMail();
62
63//----¡¡¥á¡¼¥ëÀ¸À®¤ÈÁ÷¿®
64for( $i = 0; $i < $count; $i++ ) {
65
66    for( $j = 0; $j < count( $list_data[$i] ); $j ++ ) {
67
68        $customerName = "";
69        $mailBody = "";
70        $sendFlag = "";
71
72        //-- ¸ÜµÒ̾¤ÎÊÑ´¹
73        $name = trim($list_data[$i][$j]["name"]);
74       
75        if ($name == "") {
76            $name = "¤ªµÒ";
77        }
78       
79        $customerName = htmlspecialchars($name);
80        $subjectBody = ereg_replace( "{name}", $customerName , $mail_data[$i][0]["subject"] );
81        $mailBody = ereg_replace( "{name}", $customerName ,  $mail_data[$i][0]["body"] );
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);
121if($result) {
122    echo "OK!!";
123    exit;
124} else {
125    echo "NG!!";
126    exit;
127}             
128        } else {
129            //-- ¥Æ¥­¥¹¥È¥á¡¼¥ëÇÛ¿®¤Î¾ì¹ç
130            if( $mail_data[$i][0]["mail_method"] == 2 ) {
131
132                $sendResut = MAIL_SENDING(
133                                         $list_data[$i][$j]["email"]                //¡¡¸ÜµÒ°¸Àè
134                                        ,$subjectBody                               //¡¡Subject
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            //--  HTML¥á¡¼¥ëÇÛ¿®¤Î¾ì¹ç 
145            } elseif( $mail_data[$i][0]["mail_method"] == 1 || $mail_data[$i][0]["mail_method"] == 3) {
146           
147                $sendResut = HTML_MAIL_SENDING(
148                                             $list_data[$i][$j]["email"]
149                                            ,$subjectBody
150                                            ,$mailBody
151                                            ,$objSite->data["email03"]                  //¡¡Á÷¿®¸µ¥á¡¼¥ë¥¢¥É¥ì¥¹
152                                            ,$objSite->data["company_name"]             //¡¡Á÷¿®¸µÌ¾
153                                            ,$objSite->data["email03"]                  //¡¡reply_to
154                                            ,$objSite->data["email04"]                  //¡¡return_path
155                                            ,$objSite->data["email04"]                  //¡¡errors_to
156                                                                     );
157            }
158        }
159 
160        //-- Á÷¿®´°Î»¤Ê¤é1¡¢¼ºÇԤʤé0¤ò¥á¡¼¥ëÁ÷¿®·ë²Ì¥Õ¥é¥°¤È¤·¤ÆDB¤ËÁÞÆþ
161        if( ! $sendResut ){
162            $sendFlag = "0";
163        } else {
164            $sendFlag = "1";
165           
166            // ´°Î»¤ò1¤³Áý¤ä¤¹
167            $sql = "UPDATE dtb_send_history SET complete_count = complete_count + 1 WHERE send_id = ?";
168            $conn->query( $sql, array($mail_data[$i][0]["send_id"]));
169        }
170
171        $conn->query( $sql_flag, array( $sendFlag, $mail_data[$i][0]["send_id"], $list_data[$i][$j]["customer_id"] ) );
172       
173       
174
175    }
176
177    //--- ¥á¡¼¥ëÁ´·ïÁ÷¿®´°Î»¸å¤Î½èÍý
178    $completeSql = "UPDATE dtb_send_history SET end_date = now() WHERE send_id = ?";
179    $conn->query( $completeSql, array( $time_data[$i]["send_id"] ) );
180
181    //---¡¡Á÷¿®´°Î»¡¡Êó¹ð¥á¡¼¥ë
182    $compData =  date("Yǯm·îdÆüH»þiʬ" . "  ²¼µ­¥á¡¼¥ë¤ÎÇÛ¿®¤¬´°Î»¤·¤Þ¤·¤¿¡£" );
183
184    HTML_MAIL_SENDING(
185                     $objSite->data["email03"] 
186                    ,$compData
187                    ,$mail_data[$i][0]["body"]
188                    ,$objSite->data["email03"]                  //¡¡Á÷¿®¸µ¥á¡¼¥ë¥¢¥É¥ì¥¹
189                    ,$objSite->data["company_name"]             //¡¡Á÷¿®¸µÌ¾
190                    ,$objSite->data["email03"]                  //¡¡reply_to
191                    ,$objSite->data["email04"]                  //¡¡return_path
192                    ,$objSite->data["email04"]                  //¡¡errors_to
193                 );
194                 
195    if ($_GET['mode'] = "now") {
196        header("Location: " . URL_DIR . "admin/mail/history.php");
197    }
198    echo "complete\n";
199
200}
201
202
203//--- ¥Æ¥­¥¹¥È¥á¡¼¥ëÇÛ¿®
204function MAIL_SENDING( $to, $subject, $body, $fromaddress, $from_name, $reply_to, $return_path, $errors_to="", $bcc="", $cc ="" ) {
205
206    $mail_obj = new GC_SendMail(); 
207    $mail_obj->setItem( $to, $subject, $body, $fromaddress, $from_name, $reply_to, $return_path, $errors_to, $bcc, $cc );
208       
209    if( $mail_obj->sendMail() ) {
210        return true;
211    }
212   
213}
214
215//--- HTML¥á¡¼¥ëÇÛ¿®
216function HTML_MAIL_SENDING( $to, $subject, $body, $fromaddress, $from_name, $reply_to, $return_path, $errors_to="", $bcc="", $cc ="" ) {
217
218    $html_mail_obj = new GC_SendMail();
219    $html_mail_obj->setItemHtml( $to, $subject, $body, $fromaddress, $from_name, $reply_to, $return_path, $errors_to, $bcc, $cc );
220           
221    if( $html_mail_obj->sendHtmlMail() ) {
222        return true;   
223    }
224   
225}
226
227
228?>
Note: See TracBrowser for help on using the repository browser.