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

Revision 6147, 5.0 KB checked in by naka, 20 years ago (diff)

* empty log message *

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