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

Revision 2143, 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 delete = 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 delete = 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   
91        //-- Á÷¿®´°Î»¤Ê¤é1¡¢¼ºÇԤʤé0¤ò¥á¡¼¥ëÁ÷¿®·ë²Ì¥Õ¥é¥°¤È¤·¤ÆDB¤ËÁÞÆþ
92        if( ! $sendResut ){
93             $sendFlag = "-1";
94        } else {
95            $sendFlag = "1";
96           
97            // ´°Î»¤ò1¤³Áý¤ä¤¹
98            $sql = "UPDATE dtb_send_history SET complete_count = complete_count + 1 WHERE send_id = ?";
99            $conn->query( $sql, array($mail_data[$i][0]["send_id"]) );
100        }
101
102        $conn->query( $sql_flag, array( $sendFlag, $mail_data[$i][0]["send_id"], $list_data[$i][$j]["customer_id"] ) );
103       
104       
105
106    }
107
108    //--- ¥á¡¼¥ëÁ´·ïÁ÷¿®´°Î»¸å¤Î½èÍý
109    $completeSql = "UPDATE dtb_send_history SET end_date = now() WHERE send_id = ?";
110    $conn->query( $completeSql, array( $time_data[$i]["send_id"] ) );
111
112    //---¡¡Á÷¿®´°Î»¡¡Êó¹ð¥á¡¼¥ë
113    $compData =  date("Yǯm·îdÆüH»þiʬ" . "  ²¼µ­¥á¡¼¥ë¤ÎÇÛ¿®¤¬´°Î»¤·¤Þ¤·¤¿¡£" );
114    MAIL_SENDING(
115                     $objSite->data["email03"] 
116                    ,$compData
117                    ,$mail_data[$i][0]["body"]
118                    ,$objSite->data["email03"]                  //¡¡Á÷¿®¸µ¥á¡¼¥ë¥¢¥É¥ì¥¹
119                    ,$objSite->data["company_name"]             //¡¡Á÷¿®¸µÌ¾
120                    ,$objSite->data["email03"]                  //¡¡reply_to
121                    ,$objSite->data["email04"]                  //¡¡return_path
122                    ,$objSite->data["email04"]                  //¡¡errors_to
123                 );
124   
125    if ($_GET['mode'] = "now") {
126        header("Location: /admin/mail/history.php");
127    }
128    echo "complete\n";
129
130}
131
132
133//--- ¥Æ¥­¥¹¥È¥á¡¼¥ëÇÛ¿®
134function MAIL_SENDING( $to, $subject, $body, $fromaddress, $from_name, $reply_to, $return_path, $errors_to="", $bcc="", $cc ="" ) {
135
136
137    $mail_obj = new GC_SendMail(); 
138    $mail_obj->setItem( $to, $subject, $body, $fromaddress, $from_name, $reply_to, $return_path, $errors_to, $bcc, $cc );
139       
140    if( $mail_obj->sendMail() ) {
141        return true;
142    }
143   
144}
145
146//--- HTML¥á¡¼¥ëÇÛ¿®
147function HTML_MAIL_SENDING( $to, $subject, $body, $fromaddress, $from_name, $reply_to, $return_path, $errors_to="", $bcc="", $cc ="" ) {
148
149
150    $html_mail_obj = new GC_SendMail();
151    $html_mail_obj->setItemHtml( $to, $subject, $body, $fromaddress, $from_name, $reply_to, $return_path, $errors_to, $bcc, $cc );
152
153           
154    if( $html_mail_obj->sendHtmlMail() ) {
155        return true;   
156    }
157   
158}
159
160
161?>
Note: See TracBrowser for help on using the repository browser.