source: temp/trunk/html/admin/mail/sendmail.php @ 4643

Revision 4643, 4.9 KB checked in by kakinaka, 20 years ago (diff)

blank

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1<?php
2$include_dir = realpath(dirname( __FILE__));
3require_once($include_dir."/../require.php");
4$conn = new SC_DbConn();
5$objSite = new SC_SiteInfo($conn);
6
7if($_GET['mode'] == 'now') {
8    //----¡¡Ì¤Á÷¿®¥Ç¡¼¥¿¤ò¼èÆÀ¤¹¤ë
9    $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" );
10} else {
11    $sql = "SELECT send_id FROM dtb_send_history  ";
12    $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";
13    //----¡¡30ʬËè¤ËCron¤¬Á÷¿®»þ´Ö¥Ç¡¼¥¿³Îǧ
14    $time_data = $conn->getAll($sql);
15}
16
17$count = count($time_data);
18
19if( $count > 0 ){
20    print("start sending <br />\n");
21} else {
22    print("not found <br />\n");
23    exit;
24}
25
26//---- ¥á¡¼¥ëÁ÷¿®
27for( $i = 0; $i < count( $time_data ); $i++ ) {
28
29    $sql = "SELECT * FROM dtb_send_customer WHERE send_id = ? AND (send_flag = 2 OR send_flag IS NULL)";
30    $list_data[] = $conn->getAll( $sql, array( $time_data[$i]["send_id"] ) );
31   
32    $sql = "SELECT * FROM dtb_send_history WHERE send_id = ?";
33    $mail_data[] = $conn->getAll( $sql, array(  $time_data[$i]["send_id"] ) );
34
35}
36
37//---- Á÷¿®·ë²Ì¥Õ¥é¥°ÍÑSQL
38$sql_flag ="UPDATE dtb_send_customer SET send_flag = ? WHERE send_id = ? AND customer_id = ?";
39$objMail = new GC_SendMail();
40
41//----¡¡¥á¡¼¥ëÀ¸À®¤ÈÁ÷¿®
42for( $i = 0; $i < count( $time_data ); $i++ ) {
43
44    for( $j = 0; $j < count( $list_data[$i] ); $j ++ ) {
45
46        $customerName = "";
47        $mailBody = "";
48        $sendFlag = "";
49
50        //-- ¸ÜµÒ̾¤ÎÊÑ´¹
51        $name = trim($list_data[$i][$j]["name"]);
52       
53        if ($name == "") {
54            $name = "¤ªµÒ";
55        }
56       
57        $customerName = htmlspecialchars($name);
58        $subjectBody = ereg_replace( "{name}", $customerName , $mail_data[$i][0]["subject"] );
59        $mailBody = ereg_replace( "{name}", $customerName ,  $mail_data[$i][0]["body"] );
60
61        //-- ¥Æ¥­¥¹¥È¥á¡¼¥ëÇÛ¿®¤Î¾ì¹ç   
62        if( $mail_data[$i][0]["mail_method"] == 2 ) {
63
64            $sendResut = MAIL_SENDING(
65                                         $list_data[$i][$j]["email"]                //¡¡¸ÜµÒ°¸Àè
66                                        ,$subjectBody                               //¡¡Subject
67                                        ,$mailBody                                  //¡¡¥á¡¼¥ëËÜʸ
68                                        ,$objSite->data["email03"]                  //¡¡Á÷¿®¸µ¥á¡¼¥ë¥¢¥É¥ì¥¹
69                                        ,$objSite->data["company_name"]             //¡¡Á÷¿®¸µÌ¾
70                                        ,$objSite->data["email03"]                  //¡¡reply_to
71                                        ,$objSite->data["email04"]                  //¡¡return_path
72                                        ,$objSite->data["email04"]                  //¡¡errors_to
73                                                                             );
74
75        //--  HTML¥á¡¼¥ëÇÛ¿®¤Î¾ì¹ç 
76        } elseif( $mail_data[$i][0]["mail_method"] == 1 || $mail_data[$i][0]["mail_method"] == 3) {
77           
78            $sendResut = HTML_MAIL_SENDING(
79                                             $list_data[$i][$j]["email"]
80                                            ,$subjectBody
81                                            ,$mailBody
82                                            ,$objSite->data["email03"]                  //¡¡Á÷¿®¸µ¥á¡¼¥ë¥¢¥É¥ì¥¹
83                                            ,$objSite->data["company_name"]             //¡¡Á÷¿®¸µÌ¾
84                                            ,$objSite->data["email03"]                  //¡¡reply_to
85                                            ,$objSite->data["email04"]                  //¡¡return_path
86                                            ,$objSite->data["email04"]                  //¡¡errors_to
87                                                                     );
88        }
89   
90        //-- Á÷¿®´°Î»¤Ê¤é1¡¢¼ºÇԤʤé0¤ò¥á¡¼¥ëÁ÷¿®·ë²Ì¥Õ¥é¥°¤È¤·¤ÆDB¤ËÁÞÆþ
91        if( ! $sendResut ){
92             $sendFlag = "-1";
93        } else {
94            $sendFlag = "1";
95           
96            // ´°Î»¤ò1¤³Áý¤ä¤¹
97            $sql = "UPDATE dtb_send_history SET complete_count = complete_count + 1 WHERE send_id = ?";
98            $conn->query( $sql, array($mail_data[$i][0]["send_id"]) );
99        }
100
101        $conn->query( $sql_flag, array( $sendFlag, $mail_data[$i][0]["send_id"], $list_data[$i][$j]["customer_id"] ) );
102       
103       
104
105    }
106
107    //--- ¥á¡¼¥ëÁ´·ïÁ÷¿®´°Î»¸å¤Î½èÍý
108    $completeSql = "UPDATE dtb_send_history SET end_date = now() WHERE send_id = ?";
109    $conn->query( $completeSql, array( $time_data[$i]["send_id"] ) );
110
111    //---¡¡Á÷¿®´°Î»¡¡Êó¹ð¥á¡¼¥ë
112    $compData =  date("Yǯm·îdÆüH»þiʬ" . "  ²¼µ­¥á¡¼¥ë¤ÎÇÛ¿®¤¬´°Î»¤·¤Þ¤·¤¿¡£" );
113    MAIL_SENDING(
114                     $objSite->data["email03"] 
115                    ,$compData
116                    ,$mail_data[$i][0]["body"]
117                    ,$objSite->data["email03"]                  //¡¡Á÷¿®¸µ¥á¡¼¥ë¥¢¥É¥ì¥¹
118                    ,$objSite->data["company_name"]             //¡¡Á÷¿®¸µÌ¾
119                    ,$objSite->data["email03"]                  //¡¡reply_to
120                    ,$objSite->data["email04"]                  //¡¡return_path
121                    ,$objSite->data["email04"]                  //¡¡errors_to
122                 );
123   
124    if ($_GET['mode'] = "now") {
125        header("Location: /admin/mail/history.php");
126    }
127    echo "complete\n";
128
129}
130
131
132//--- ¥Æ¥­¥¹¥È¥á¡¼¥ëÇÛ¿®
133function MAIL_SENDING( $to, $subject, $body, $fromaddress, $from_name, $reply_to, $return_path, $errors_to="", $bcc="", $cc ="" ) {
134
135
136    $mail_obj = new GC_SendMail(); 
137    $mail_obj->setItem( $to, $subject, $body, $fromaddress, $from_name, $reply_to, $return_path, $errors_to, $bcc, $cc );
138       
139    if( $mail_obj->sendMail() ) {
140        return true;
141    }
142   
143}
144
145//--- HTML¥á¡¼¥ëÇÛ¿®
146function HTML_MAIL_SENDING( $to, $subject, $body, $fromaddress, $from_name, $reply_to, $return_path, $errors_to="", $bcc="", $cc ="" ) {
147
148
149    $html_mail_obj = new GC_SendMail();
150    $html_mail_obj->setItemHtml( $to, $subject, $body, $fromaddress, $from_name, $reply_to, $return_path, $errors_to, $bcc, $cc );
151
152           
153    if( $html_mail_obj->sendHtmlMail() ) {
154        return true;   
155    }
156   
157}
158
159
160?>
Note: See TracBrowser for help on using the repository browser.