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

Revision 13168, 8.4 KB checked in by matsumoto, 19 years ago (diff)
RevLine 
[12240]1<?php
[8]2/*
[17]3 * Copyright(c) 2000-2007 LOCKON CO.,LTD. All Rights Reserved.
[8]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) {
[12820]13    exit;
[8]14}
15
[12820]16
[8]17if($_GET['mode'] == 'now') {
[12820]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" );
[8]20} else {
[12820]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);
[8]32}
33
34$count = count($time_data);
35
36if( $count > 0 ){
[12820]37    print("start sending <br />\n");
[8]38} else {
[12820]39    print("not found <br />\n");
40    exit;
[8]41}
42
43//---- ¥á¡¼¥ëÁ÷¿®
44for( $i = 0; $i < count( $time_data ); $i++ ) {
45
[12820]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"] ) );
[8]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();
[12803]57
[8]58//----¡¡¥á¡¼¥ëÀ¸À®¤ÈÁ÷¿®
59for( $i = 0; $i < count( $time_data ); $i++ ) {
60
[12820]61    for( $j = 0; $j < count( $list_data[$i] ); $j ++ ) {
[8]62
[12820]63        $customerName = "";
64        $mailBody = "";
65        $sendFlag = "";
[8]66
[12821]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"] );
[8]77
[12955]78        //-- ¥á¥ë¥Þ¥¬ÇÛ¿®¤ò¥Ö¥ì¥¤¥óÏ¢·È¤Ç¹Ô¤¦¾ì¹ç
[13139]79        if(MELMAGA_MOBILE_SEND){
[13167]80           
81            print_r(MELMAGA_SENDING);
[13157]82            $sendResut = MELMAGA_SENDING(
[13165]83                                         $list_data[$i][$j]["email"]   //¡¡¸ÜµÒ°¸Àè
84                                        ,$subjectBody                  //¡¡Subject
85                                        ,$mailBody                     //¡¡¥á¡¼¥ëËÜʸ
86                                        ,$objSite->data["email03"]     //¡¡Á÷¿®¸µ¥á¡¼¥ë¥¢¥É¥ì¥¹
87                                        ,$objSite->data["company_name"]//¡¡Á÷¿®¸µÌ¾
88                                        ,$objSite->data["email03"]     //¡¡reply_to
89                                        ,$objSite->data["email04"]     //¡¡return_path
90                                        ,$objSite->data["email04"]     //¡¡errors_to
91                                                                       );
[13163]92            $mail_options = array(   
93                        //¥Ö¥ì¥¤¥ó¤ÎSMTP¥µ¡¼¥Ð¡¼IP¥¢¥É¥ì¥¹
94                              'host' => "127.0.1"
95                             ,'port' => "25"                 
[13153]96                                          );
97             
[13145]98                    print_r($sendResut);
99                     
100                    $decoder =& new Mail_mimeDecode($sendResut);
[13146]101                    //print_r($decoder);
[13145]102                    $parts = $decoder->getSendArray();
[13146]103                    //print_r($parts);
[13145]104                    list($recipients, $header, $body) = $parts;
105                     
106                    //$mailSend =& Mail::factory("SMTP", $mail_options);
107                    $mailSend =& Mail::factory("SMTP");
[13146]108                    //print_r($mailSend);
[13145]109                    $mailSend->send($recipients, $header, $body);
110                    break;             
[13143]111                 
[12949]112        } else {
[12940]113            //-- ¥Æ¥­¥¹¥È¥á¡¼¥ëÇÛ¿®¤Î¾ì¹ç
114            if( $mail_data[$i][0]["mail_method"] == 2 ) {
[8]115
[12940]116                $sendResut = MAIL_SENDING(
117                                         $list_data[$i][$j]["email"]                //¡¡¸ÜµÒ°¸Àè
118                                        ,$subjectBody                               //¡¡Subject
119                                        ,$mailBody                                  //¡¡¥á¡¼¥ëËÜʸ
120                                        ,$objSite->data["email03"]                  //¡¡Á÷¿®¸µ¥á¡¼¥ë¥¢¥É¥ì¥¹
121                                        ,$objSite->data["company_name"]             //¡¡Á÷¿®¸µÌ¾
122                                        ,$objSite->data["email03"]                  //¡¡reply_to
123                                        ,$objSite->data["email04"]                  //¡¡return_path
124                                        ,$objSite->data["email04"]                  //¡¡errors_to
125                                                                         );
[13013]126                                                                         
[12821]127
[12940]128            //--  HTML¥á¡¼¥ëÇÛ¿®¤Î¾ì¹ç 
129            } elseif( $mail_data[$i][0]["mail_method"] == 1 || $mail_data[$i][0]["mail_method"] == 3) {
[12820]130           
[12940]131                $sendResut = HTML_MAIL_SENDING(
132                                             $list_data[$i][$j]["email"]
133                                            ,$subjectBody
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            }
[12949]142        }
[12940]143 
[12820]144        //-- Á÷¿®´°Î»¤Ê¤é1¡¢¼ºÇԤʤé0¤ò¥á¡¼¥ëÁ÷¿®·ë²Ì¥Õ¥é¥°¤È¤·¤ÆDB¤ËÁÞÆþ
145        if( ! $sendResut ){
146             $sendFlag = "-1";
147        } else {
148            $sendFlag = "1";
149           
150            // ´°Î»¤ò1¤³Áý¤ä¤¹
151            $sql = "UPDATE dtb_send_history SET complete_count = complete_count + 1 WHERE send_id = ?";
152            $conn->query( $sql, array($mail_data[$i][0]["send_id"]) );
153        }
[8]154
[12820]155        $conn->query( $sql_flag, array( $sendFlag, $mail_data[$i][0]["send_id"], $list_data[$i][$j]["customer_id"] ) );
[12940]156       
157       
[8]158
[12820]159    }
[8]160
[12820]161    //--- ¥á¡¼¥ëÁ´·ïÁ÷¿®´°Î»¸å¤Î½èÍý
162    $completeSql = "UPDATE dtb_send_history SET end_date = now() WHERE send_id = ?";
163    $conn->query( $completeSql, array( $time_data[$i]["send_id"] ) );
[11808]164
[12820]165    //---¡¡Á÷¿®´°Î»¡¡Êó¹ð¥á¡¼¥ë
166    $compData =  date("Yǯm·îdÆüH»þiʬ" . "  ²¼µ­¥á¡¼¥ë¤ÎÇÛ¿®¤¬´°Î»¤·¤Þ¤·¤¿¡£" );
[8]167
[12971]168    HTML_MAIL_SENDING(
[12820]169                     $objSite->data["email03"] 
170                    ,$compData
171                    ,$mail_data[$i][0]["body"]
172                    ,$objSite->data["email03"]                  //¡¡Á÷¿®¸µ¥á¡¼¥ë¥¢¥É¥ì¥¹
173                    ,$objSite->data["company_name"]             //¡¡Á÷¿®¸µÌ¾
174                    ,$objSite->data["email03"]                  //¡¡reply_to
175                    ,$objSite->data["email04"]                  //¡¡return_path
176                    ,$objSite->data["email04"]                  //¡¡errors_to
177                 );
178                 
179    if ($_GET['mode'] = "now") {
180        header("Location: " . URL_DIR . "admin/mail/history.php");
181    }
182    echo "complete\n";
183
[8]184}
185
186
[13100]187//--- ¥á¥ë¥Þ¥¬ÇÛ¿®¡ÊBLAYNÏ¢·È¤Î¾ì¹ç¡Ë
188function MELMAGA_SENDING( $to, $subject, $body, $fromaddress, $from_name, $reply_to, $return_path, $errors_to="", $bcc="", $cc ="" ) {
189
190
[13166]191    $html_mail_obj = new GC_SendMail(); 
[13162]192    $html_mail_obj->setItemHtml( $to, $subject, $body, $fromaddress, $from_name, $reply_to, $return_path, $errors_to, $bcc, $cc );
[13159]193   
[13168]194    break;
[13100]195}
196
[8]197//--- ¥Æ¥­¥¹¥È¥á¡¼¥ëÇÛ¿®
198function MAIL_SENDING( $to, $subject, $body, $fromaddress, $from_name, $reply_to, $return_path, $errors_to="", $bcc="", $cc ="" ) {
199
200
[12820]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       
[13013]204    if( $mail_obj->sendMail() ) {
205        return true;
206    }
[12820]207   
[8]208}
209
210//--- HTML¥á¡¼¥ëÇÛ¿®
211function HTML_MAIL_SENDING( $to, $subject, $body, $fromaddress, $from_name, $reply_to, $return_path, $errors_to="", $bcc="", $cc ="" ) {
212
213
[12820]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 );
[8]216
[12820]217           
218    if( $html_mail_obj->sendHtmlMail() ) {
219        return true;   
220    }
221   
[8]222}
223
224
225?>
Note: See TracBrowser for help on using the repository browser.