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

Revision 13391, 8.2 KB checked in by uehara, 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
[13293]16//¥ê¥¢¥ë¥¿¥¤¥àÇÛ¿®¥â¡¼¥É¤¬¥ª¥ó¤Î¤È¤­
[8]17if($_GET['mode'] == 'now') {
[12820]18    //----¡¡Ì¤Á÷¿®¥Ç¡¼¥¿¤ò¼èÆÀ¤¹¤ë
[13301]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" );
[13389]20
[8]21} else {
[12820]22   
23    // postgresql ¤È mysql ¤È¤ÇSQL¤ò¤ï¤±¤ë
24    if (DB_TYPE == "pgsql") {
25        $sql = "SELECT send_id FROM dtb_send_history  ";
26        $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";
27    }else if (DB_TYPE == "mysql") {
28        $sql = "SELECT send_id FROM dtb_send_history  ";
29        $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";
30    }   
31    //----¡¡30ʬËè¤ËCron¤¬Á÷¿®»þ´Ö¥Ç¡¼¥¿³Îǧ
32    $time_data = $conn->getAll($sql);
[8]33}
34
35$count = count($time_data);
36
[13378]37
[8]38if( $count > 0 ){
[12820]39    print("start sending <br />\n");
[8]40} else {
[12820]41    print("not found <br />\n");
42    exit;
[8]43}
44
[13358]45//---- ¥á¡¼¥ëÁ÷¿®½àÈ÷
[13377]46for( $i = 0; $i < $count; $i++ ) {
[8]47
[12820]48    $sql = "SELECT * FROM dtb_send_customer WHERE send_id = ? AND (send_flag = 2 OR send_flag IS NULL)";
49    $list_data[] = $conn->getAll( $sql, array( $time_data[$i]["send_id"] ) );
50   
51    $sql = "SELECT * FROM dtb_send_history WHERE send_id = ?";
52    $mail_data[] = $conn->getAll( $sql, array(  $time_data[$i]["send_id"] ) );
[8]53
54}
55
56//---- Á÷¿®·ë²Ì¥Õ¥é¥°ÍÑSQL
57$sql_flag ="UPDATE dtb_send_customer SET send_flag = ? WHERE send_id = ? AND customer_id = ?";
58$objMail = new GC_SendMail();
[12803]59
[13380]60
[13391]61
[8]62//----¡¡¥á¡¼¥ëÀ¸À®¤ÈÁ÷¿®
[13378]63for( $i = 0; $i < $count; $i++ ) {
[8]64
[12820]65    for( $j = 0; $j < count( $list_data[$i] ); $j ++ ) {
[13391]66print($count);
67print_r($list_data[$i]);
68exit;
[12820]69        $customerName = "";
70        $mailBody = "";
71        $sendFlag = "";
[8]72
[12821]73        //-- ¸ÜµÒ̾¤ÎÊÑ´¹
74        $name = trim($list_data[$i][$j]["name"]);
75       
76        if ($name == "") {
77            $name = "¤ªµÒ";
78        }
79       
80        $customerName = htmlspecialchars($name);
81        $subjectBody = ereg_replace( "{name}", $customerName , $mail_data[$i][0]["subject"] );
82        $mailBody = ereg_replace( "{name}", $customerName ,  $mail_data[$i][0]["body"] );
[8]83
[13379]84
[12955]85        //-- ¥á¥ë¥Þ¥¬ÇÛ¿®¤ò¥Ö¥ì¥¤¥óÏ¢·È¤Ç¹Ô¤¦¾ì¹ç
[13233]86        if(MELMAGA_SEND_BLAYN){
[13244]87           
[13243]88            //-- ʸ»ú¤òÆüËܸì¤ËÀßÄê
[13205]89            Mb_language( "Japanese" );
[13273]90                 
[13269]91            //-- Á÷¿®¤¹¤ë¥á¡¼¥ë¤ÎÆâÍÆ¤ÈÁ÷¿®Àè
[13244]92            $sendResut = array(
[13245]93                          "to" => $list_data[$i][$j]["email"]        //¡¡¸ÜµÒ°¸Àè
94                    ,"subject" => mb_encode_mimeheader($subjectBody) //¡¡Subject 
95                       ,"from" => $objSite->data["email03"]          //¡¡Á÷¿®¸µ¥á¡¼¥ë¥¢¥É¥ì¥¹
96                  ,"replay_to" => $objSite->data["email03"]          //¡¡reply_to
[13267]97                ,"return_path" => $objSite->data["email04"]          //¡¡return_path
[13244]98                                                                       );
[13273]99            //-- ¥á¥Ã¥»¡¼¥¸¤Î¹½ÃÛ
100            $html_param['head_charset'] = "ISO-2022-JP";
101            $html_param['html_encoding'] = "ISO-2022-JP";
[13275]102            $html_param['html_charset'] = "JIS";
103           
[13243]104            //-- ¥Ö¥ì¥¤¥óSMTP¥µ¡¼¥Ð¡¼IP¥¢¥É¥ì¥¹
[13201]105            $param = array(   
[13239]106                       'host' => "210.188.254.83"
107                      ,'port' => "25"                 
[13244]108                                                  );
109            //-- Mail_mime¥ª¥Ö¥¸¥§¥¯¥ÈºîÀ®
[13275]110            $mail_mimeObj = new Mail_mime();
[13243]111           
[13244]112            //-- Mail_mime¥ª¥Ö¥¸¥§¥¯¥È¤ËHTML¤ÎËÜʸ¤òÄɲÃ
[13245]113            $mailBody = mb_convert_encoding($mailBody, "JIS", CHAR_CODE);
[13275]114            $mail_mimeObj->setHTMLBody($mailBody);
[13243]115           
[13275]116            $body = $mail_mimeObj->get($html_param);
117            $header = $mail_mimeObj->headers($sendResut);
[13243]118           
[13275]119            //-- PEAR::Mail¤ò»È¤Ã¤Æ¥á¡¼¥ëÁ÷¿®¥ª¥Ö¥¸¥§¥¯¥ÈºîÀ®
120            $mailObj =& Mail::factory("smtp", $param);
[13243]121            // ¥á¡¼¥ëÁ÷¿®
[13276]122            $result = $mailObj->send($sendResut["to"], $header, $body);
[13379]123
124        } else {
[12940]125            //-- ¥Æ¥­¥¹¥È¥á¡¼¥ëÇÛ¿®¤Î¾ì¹ç
126            if( $mail_data[$i][0]["mail_method"] == 2 ) {
[8]127
[12940]128                $sendResut = MAIL_SENDING(
129                                         $list_data[$i][$j]["email"]                //¡¡¸ÜµÒ°¸Àè
130                                        ,$subjectBody                               //¡¡Subject
131                                        ,$mailBody                                  //¡¡¥á¡¼¥ëËÜʸ
132                                        ,$objSite->data["email03"]                  //¡¡Á÷¿®¸µ¥á¡¼¥ë¥¢¥É¥ì¥¹
133                                        ,$objSite->data["company_name"]             //¡¡Á÷¿®¸µÌ¾
134                                        ,$objSite->data["email03"]                  //¡¡reply_to
135                                        ,$objSite->data["email04"]                  //¡¡return_path
136                                        ,$objSite->data["email04"]                  //¡¡errors_to
137                                                                         );
[13013]138                                                                         
[12821]139
[12940]140            //--  HTML¥á¡¼¥ëÇÛ¿®¤Î¾ì¹ç 
141            } elseif( $mail_data[$i][0]["mail_method"] == 1 || $mail_data[$i][0]["mail_method"] == 3) {
[12820]142           
[12940]143                $sendResut = HTML_MAIL_SENDING(
144                                             $list_data[$i][$j]["email"]
145                                            ,$subjectBody
146                                            ,$mailBody
147                                            ,$objSite->data["email03"]                  //¡¡Á÷¿®¸µ¥á¡¼¥ë¥¢¥É¥ì¥¹
148                                            ,$objSite->data["company_name"]             //¡¡Á÷¿®¸µÌ¾
149                                            ,$objSite->data["email03"]                  //¡¡reply_to
150                                            ,$objSite->data["email04"]                  //¡¡return_path
151                                            ,$objSite->data["email04"]                  //¡¡errors_to
152                                                                     );
153            }
[12949]154        }
[12940]155 
[12820]156        //-- Á÷¿®´°Î»¤Ê¤é1¡¢¼ºÇԤʤé0¤ò¥á¡¼¥ëÁ÷¿®·ë²Ì¥Õ¥é¥°¤È¤·¤ÆDB¤ËÁÞÆþ
157        if( ! $sendResut ){
[13302]158            $sendFlag = "0";
[12820]159        } else {
160            $sendFlag = "1";
161           
162            // ´°Î»¤ò1¤³Áý¤ä¤¹
163            $sql = "UPDATE dtb_send_history SET complete_count = complete_count + 1 WHERE send_id = ?";
[13299]164            $conn->query( $sql, array($mail_data[$i][0]["send_id"]));
[12820]165        }
[8]166
[12820]167        $conn->query( $sql_flag, array( $sendFlag, $mail_data[$i][0]["send_id"], $list_data[$i][$j]["customer_id"] ) );
[12940]168       
169       
[8]170
[12820]171    }
[8]172
[12820]173    //--- ¥á¡¼¥ëÁ´·ïÁ÷¿®´°Î»¸å¤Î½èÍý
174    $completeSql = "UPDATE dtb_send_history SET end_date = now() WHERE send_id = ?";
175    $conn->query( $completeSql, array( $time_data[$i]["send_id"] ) );
[11808]176
[12820]177    //---¡¡Á÷¿®´°Î»¡¡Êó¹ð¥á¡¼¥ë
178    $compData =  date("Yǯm·îdÆüH»þiʬ" . "  ²¼µ­¥á¡¼¥ë¤ÎÇÛ¿®¤¬´°Î»¤·¤Þ¤·¤¿¡£" );
[8]179
[12971]180    HTML_MAIL_SENDING(
[12820]181                     $objSite->data["email03"] 
182                    ,$compData
183                    ,$mail_data[$i][0]["body"]
184                    ,$objSite->data["email03"]                  //¡¡Á÷¿®¸µ¥á¡¼¥ë¥¢¥É¥ì¥¹
185                    ,$objSite->data["company_name"]             //¡¡Á÷¿®¸µÌ¾
186                    ,$objSite->data["email03"]                  //¡¡reply_to
187                    ,$objSite->data["email04"]                  //¡¡return_path
188                    ,$objSite->data["email04"]                  //¡¡errors_to
189                 );
[13382]190               
[12820]191    if ($_GET['mode'] = "now") {
192        header("Location: " . URL_DIR . "admin/mail/history.php");
193    }
194    echo "complete\n";
195
[8]196}
197
198
199//--- ¥Æ¥­¥¹¥È¥á¡¼¥ëÇÛ¿®
200function MAIL_SENDING( $to, $subject, $body, $fromaddress, $from_name, $reply_to, $return_path, $errors_to="", $bcc="", $cc ="" ) {
201
[12820]202    $mail_obj = new GC_SendMail(); 
203    $mail_obj->setItem( $to, $subject, $body, $fromaddress, $from_name, $reply_to, $return_path, $errors_to, $bcc, $cc );
204       
[13013]205    if( $mail_obj->sendMail() ) {
206        return true;
207    }
[12820]208   
[8]209}
210
211//--- HTML¥á¡¼¥ëÇÛ¿®
212function HTML_MAIL_SENDING( $to, $subject, $body, $fromaddress, $from_name, $reply_to, $return_path, $errors_to="", $bcc="", $cc ="" ) {
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 );
216           
217    if( $html_mail_obj->sendHtmlMail() ) {
218        return true;   
219    }
220   
[8]221}
222
223
224?>
Note: See TracBrowser for help on using the repository browser.