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

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